How can dynamic HTML be put into a PDF using ColdFusion?
This is in relation to my question about getting IE to work properly with a CFDIV.
What I am trying to do is something similar to this
<cfdocument
name="table"
format="PDF">
foo
<cfdiv id="content" bind="cfc:TestCFC.displayTable({filters})"></cfdiv>
bar
</cfdocument>
however when I open my PDF document, I only see
foo
bar
I would like a solution that uses the CFDIV with the bind, however if that is not an option than any solution will do.
You can't use bind parameters for pdfs because the bind parameters are executed via AJAX on the client. You'll need to do something like this instead:
<cfdocument name="table" format="PDF">
foo
<cfdiv id="content"><cfoutput>#TestCFC.displayTable({filters})#</cfoutput></cfdiv>
bar
</cfdocument>
And you'll need to get the filters argument in there via some other method than a bind to another element. Possibly a FORM or URL variable when the user clicks the link or button to generate the PDF.
Related
I am using jquery featherlight (https://github.com/noelboss/featherlight) after trying to get jquery lightbox (https://lokeshdhakar.com/projects/lightbox2/) to work. I am using DataTables to generate a list. One of the items in the table is a link to a php page that returns links. The problem is I am calling an external PHP page that generates a list of links. So my link code is like this:
<i class="fas fa-link fa-lg"></i>
The page "lenker.php" does a search and outputs html code. It looks fine in the chrome inspector. But the popup is empty. If I link to another page with the code hardcoded it shows fine. Why does it not show when it is generated on the fly? The html code looks just fine like this:
<div><a class="external" href="http://databank.artsdatabanken.no/FremmedArt2012/N63753" data-featherlight="ajax">fremmedartsvurdering 2012 for edelgran</a></div>
<div><a class="external" href="http://eol.org/pages/1033070" data-featherlight="ajax">edelgran hos Encyclopedia of Life</a></div>
<div><a class="external" href="http://linnaeus.nrm.se/flora/barr/pina/abies/abiealb.html" data-featherlight="ajax">edelgran i Virtuella floran, Sverige</a></div>
but the popup opens and then resizes to almost nothing since there is no content. Featherlight does not need any other initialization since it looks for data-featherlight="ajax".
Is the problem that datatable is dynamic content?
jQuery ajax expects one object so I solved this with enclosing my content in one DIV.
I have an application for customer and product management that has many screens/pages. I would like certain pages to be printable and exportable to PDF.
To print a document, its a simple case of providing a CSS stylesheet for #Print media which strips a lot of the regular styling. However, when generating the PDF I noticed the <cfdocument> and <cfhtmltopdf> tags both want the an entire HTML page to render (including <head> tags).
This means that it doesn't recognise the purpose of the PDF as being for print and doesn't pick up the #Print styles. Currently I'm having to make a seperate makepdf.cfm page and repeat the HTML of the page I want to export along with including ONLY the print CSS stylesheet.
This seems a bit crazy because I'll have to update the makepdf.cfm page each and everytime I change a main application screen that can be printed/exported to pdf.
Is there a better way to achieving what I'm trying to do?
I am not sure how your CSS is organized, but I had a similar situation where I needed to print various content off the screen. My solution was to use an AJAX call (CFAJAXPROXY) in Javascript to a CFC in order to set a CF session variable with the DIV content and then call my print page which will output the content with the cfhtmltopdf tag. My experience has been that the CSS must be included in within whichever PDF generation tag you are using.
For example:
<div id="myContent">content on my page to print</div>
And a button to print
<button onclick="printContent('myContent')">Print</button>
The onclick calls the following in the Javascript:
var printContent = function(_contentDiv){
var _content = $('#' + _contentDiv).html();
var _setContent = _cfc.setContent(_content);
window.location.href = 'printPage.cfm';
}
The "_cfc" is defined in a cfajaxproxy call.
The CF function that's going to get called looks something like the following:
<cfcomponent>
<cffunction access="remote" name="setContent" returntype="string">
<cfargument name="_content" required="yes" type="string">
<cfset session.content = _content>
<cfreturn "whateveryouwant">
</cffunction>
</cfcomponent>
And the printPage.cfm might look like this (I use Bootstrap as my CSS):
<cfhtmltopdf>
<link href="css/bootstrap.css" rel="Stylesheet" type="text/css"></link>
<cfoutput>#session.content#</cfoutput>
</cfhtmltopdf>
This is obviously a bare bones solution, but it works. I would imagine that if you needed different CSS pages, you could set the HREF value in the link tag as a session parameter as well
Assuming you're using a link tag in the head you can try to use cfinclude inside style tags to include the css file. cfdocument seems to do better with inline styles.
I ended up passing a url flag pdf=0/1, then in the template simply add a cfif around whatever content you want to toggle.
I'm trying to get it to recognize FontAwesome and Google Charts at this point. Seems to help so far.
I need to be able give users a link to my site with a parameter that will control their experience on the destination page, but, of course, Moqui does not allow parameters to be passed as a GET transaction. What are ways that I can work around that? It needs to be something that can be sent in an email, via sms and audibly.
An error message would be helpful know exactly what you are running into, but it sounds like the constraint to mitigate XSRF attacks.
The error message for this situation explains the issue and the recommended solution: "Cannot run screen transition with actions from non-secure request or with URL parameters for security reasons (they are not encrypted and need to be for data protection and source validation). Change the link this came from to be a form with hidden input fields instead."
You can pass URL parameters to screens to be used in code that prepares data for presentation, but not to transitions for code that processes input. The solution is to use a hidden form with a link or button to submit the form (that can be styled as a link or button or however you want). This is slightly more HTML than a plain hyperlink with URL parameters, but not a lot more and there are examples in various places in the Moqui itself.
If you are using an XML Screen/Form you can use the link element to do this with the #link-type attribute set to "hidden-form" or "hidden-form-link" (which just uses a hyperlink styled widget instead of a button styled one). If the #link-type attribute is set to "auto" (which is the default) it will use a hidden-form automatically if link goes to a transition with actions.
In plain HTML one possible approach looks something like this:
<button type="submit" form="UserGroupMemberList_removeLink_0">Remove</button>
<form method="post" action=".../EditUserGroups/removeGroup" name="UserGroupMemberList_removeLink_0">
<input type="hidden" name="partyId" value="EX_JOHN_DOE">
<input type="hidden" name="userGroupId" value="ADMIN">
</form>
Note that the button element refers to the form to submit, so can be placed anywhere in the HTML file and the form element can be placed at the end or anywhere that is out of the way (to avoid issues with nested forms which are not allowed in HTML).
is there a way to alter the rendered HTML page in webbrowser control? What i need is to alter the rendered HTML Page in my webbrowser control to highlight selected text.
What i did is use a webclient and use the webclient.Downloadstring() to get the source code of the page, Highlight specific text then write it again in webbrowser. problm is, images along with that page does not appear since they are rendered as relative path.
Is there a way to solve this problem? Is there a way to detect images in a webbrowser control?
Not sure why you need to change the HTML to lighlight text, why not use IHighlightRenderingServices?
To specify a base url when loading HTML string you need to use the document's IPersistMoniker interface and specify a url in your IMoniker implementation.
I suggest you do it a different way, download and replace the text using the webbrowser control, this way your links will work. All you do is replace whatever is in the Search TextBox with the following, say the search term is "hello", then you replace all occurances of hello with the following:
<font color="yellow">hello</font>
Of course, this HTML can be replaced with the SPAN tag (which is an inline version of the DIV tag, so your lines wont break using SPAN, but will using DIV). But in either case, both these tags have a style attribute, where you can use CSS to change its color or a zillion other properties that are CSS compatible, like follows:
<SPAN style="background-color: yellow;">hello</SPAN>
Of course, there are a zillion other ways to change color using HTML, feel free to search the web for more if you want.
Now, you can use the .Replace() function in dotnet to do this (replace the searched text), it's very easy. So, you can Get the Whole document as a string using .DocumentText, and once all occurances are replaced (using .Replace()), you can set it back to .DocumentText (so, you're using .DocumentText to get the original string, and setting .DocumentText with the replaced string). Of course, you probably don't want to do this to items inside the actual HTML, so you can just loop through all the elements on the page by doing a For Each loop over all elements like below:
For Each someElement as HTMLElement in WebBrowser1.Document.All
And each element will have a .InnerText/.InnerHTML and .OuterText/.OuterHTML that you can Get (read from) and Set (overwrite with replaced text).
Of course, for your needs, you'd probably just want to be replacing and overwriting the .InnerText and/or the .OuterText.
If you need more help, let me know. In either case, i'd like to know how it worked out for you anyway, or if there is anything more any of us can do to add value to your problem. Cheers.
I am able to create a simple pdf using iText api inside a struts action class.
The data that should be passed into the pdf is generated on screen based on user search parameters.
What I am wondering is how I can pass the data into the struts action so it can be displayed in the pdf?
Thanks in advance.
Similar question is already here. You just need to transfer everything that is on the page to struts action. I would do it like so:
JSP:
<div id="content">
wrap everything generated in here
</div>
<html:hidden styleId="hiddenHtml" name="hiddenHtml"/>
<html:submit onclick="setContentAsParam();">Export PDF</html:submit>
JS:
function setContentAsParam() {
document.getElementById('hiddenHtml').value = document.getElementById('content').innerHTML
}
This will set all the HTML to a action class property hiddenHtml. Get back if anything won't work, I wrote this out of my head without a test :)