Create Multiple pdfs to a directory in Coldfusion - pdf

I am trying to create multiple pdfs and save them to a directory. I have a query based off a Appid. For each appid i need to create a pdf and store in the location. I am able to create the pdf for one appid. When I try to create pdf for more than one appid, the data is being added to the current pdf. Below is my code. Please advice as to what is going wrong here.
<cfquery name="getdetails" datasource="#CSTTDB#" username="#CSTTUSR#" password="#CSTTPWD#">
select a.motsid,B.APP,B.ITCONTACT,B.STD,B.ED,B.DIRECTOR,a.tool,a.upddate,a.EAQUESTION from bnsit.TBLEAMGMT a,scott.tblaccessmgmt b
where A.MOTSID = b.motsid
and a.motsid = '16'
and a.recid = '28'
and a.EAQUESTION = 'Yes'
</cfquery>
<cfif getdetails.recordcount gt 0>
<cfloop query="getdetails">
<cfdocument
format="pdf"
srcfile="\\wiwauk4colddw11.itservices.sbc.com\ITUPCOMP\pdf\"
filename="#getdetails.motsid#_#dateformat(upddate,"mmddyy")#_eareport.pdf"
overwrite="yes">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Emergency Access BNSIT - #getdetails.motsid#</title>
</head>
<style type="text/css" media="print">
td{
width=50%;
}
.tpx td{
border: solid 1px black;
}
</style>
<body>
<img src="email_header_plain.jpg" align="center" border= "0" alt="Header">
<p align="center">
<font size="+2" color="navy"> <strong>EMERGENCY ACCESS BNSIT</strong></font>
</p>
<br>
<cfoutput>
<cfset timenow = dateformat(now(),'mm/dd/yyyy')>
<TABLE id="mytable" align="center" class="tpx" bgcolor="azure" border="1" width="80%">
<tr>
<tr>
<th align="left"><strong>MOTSID:</strong></th>
<th align="left">#motsid#</th>
</tr>
<tr>
<th align="left"><strong>Application Name:</strong></th>
<th align="left">#app#</th>
</tr>
<tr>
<th align="left"><strong>IT Contact:</strong></th>
<th align="left">#itcontact#</th>
</tr>
<tr>
<th align="left"><strong>STD:</strong></th>
<th align="left">#STD#</th>
</tr>
<tr>
<th align="left"><strong>Director:</strong></th>
<th align="left">#director#</th>
</tr>
<tr>
<th align="left"><strong>ED:</strong></th>
<th align="left">#ED#</th>
</tr>
<tr>
<th align="left"><strong>Access Provisioning Tool:</strong></th>
<th align="left"> </th>
</tr>
<tr>
<th align="left"><strong>Emergency Access Tool:</strong></th>
<th align="left">#tool#</th>
</tr>
<tr>
<th align="left"><strong>Confirmation Received Date:</strong></th>
<th align="left">#dateformat(upddate,"mm/dd/yyyy")#</th>
</tr>
</table>
</cfoutput>
</body>
</html>
</cfdocument>
</cfloop>
<cffile action="COPY" source="\\wiwauk4colddw11.itservices.sbc.com\ITUPCOMP\pdf\#getdetails.motsid#_#dateformat(upddate,"mmddyy")#_eareport.pdf" destination="\\135.16.235.36\devcompliance\pdfreports\">
</cfif>
EDIT: I have updated the code above, I am trying to copy the created pdf file from one location to another server. The pdf file is being create fine in the source folder with the given naming convention.
But im am getting below error at the cffile copy. any thoughts please?

This code
<cfdocument
format="pdf"
srcfile="\\wiwauk4colddw11.itservices.sbc.com\ITUPCOMP\pdf\"
filename="testpdf.pdf"
overwrite="yes">
is creating a single PDF file of the name "testpdf.pdf". The contents are created within this tag, by looping over the query content.
Instead, move your CFLOOP to outside the CFDOCUMENT tag. Now, for each record, you'll create a new PDF with the content of a single record's worth of data.
BUT, you'll also have to change the name of the file being created to be dynamic:
<cfloop query="getdetails">
<cfdocument
format="pdf"
srcfile="\\wiwauk4colddw11.itservices.sbc.com\ITUPCOMP\pdf\"
filename="testpdf_#getdetails.motsid#.pdf"
overwrite="yes">
<!--- HTML content --->
</cfdocument>
</cfloop>
This will create a new PDF file with a name unique to each motsid. Otherwise, you'll just keep re-creating a single file named "testpdf.pdf" that will ultimately have the contents of the last record from the query.

Related

How to make subtitles in Quasar table

I working on Vue3 with Quasar/cli.
How to make this category dividers (blue subtitles) with Quasar component qTable or qMarkupTable? screen
Ive tried to figure out body slots but I couldnt
Link to qTable API doc
https://quasar.dev/vue-components/table#introduction
Link to qMarkupTable API doc
https://quasar.dev/vue-components/markup-table#introduction
For QMarkupTable, add a row whose TD spans all the columns:
<q-markup-table>
<thead>
<tr>
<th>№</th>
<th>Name</th>
<th>Code</th>
<th>Diff</th>
</tr>
</thead>
<tbody>
<tr class="bg-primary text-white">
<td colspan="4">Medicines</td>
</tr>
<tr>
<td>1</td>
<td>Mukosolvan</td>
<td>101492</td>
<td class="text-negative">1</td>
</tr>
</tbody>
</q-markup-table>
QMarkupTable is a regular HTML table - it just applies the proper styling on it, everything else is the same HTML you've been studying as a student.

Different ways of using locators to access the rows in a table?

I am trying to learn proper use of locators to find nested elements. Using a modified table from w3school (for illustration porpouses), what is a good way of collecting the row elements belonging to the tbody (while exclude those belonging to thead)?
I was thinking:
element(by.tagName('tbody')).element.all(by.tagName('tr'))
This does not work since a sublocator can not be a an elementArrayFinder (if I have understood correctly).
Is it possible to write:
element.all(by.css('tbody tr')) ?
(I will try that last tomorrow after a long day).
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2>HTML Table</h2>
<table>
<thead>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<thead>
<tbody>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</tbody>
</table>
</body>
</html>
For nested selection in Protrator, you have to all diretly to the previous all method call like,
element(by.tagName('tbody')).all(by.tagName('tr'))
Even you can use to select the deep child like this,
element(by.tagName('tbody')).all(by.tagName('td'))
Yes. by.css('tbody tr') is for finding element by css selector. Using them in element.all() will return all the element matching the css selector.
element.all(by.css('tbody tr'));
As it is tr a immediated child, you can try this as well,
element.all(by.css('tbody>tr'));

How to "firmly" locate an element in a table? Selenium

How can I locate an element "1988" (the fourth line) in the following table:
<table border="0" width="820" cellpadding="2" cellspacing="0">
<tbody>
<tr valign="top">
<td class="default" width="100%">Results <b>1</b> to <b>10</b> of <b>1988</b></td>
</tr>
<tr valign="top">
<td class="default" bgcolor="#C0C0C0"> <font class="resultsheader"> ...etc
</tr>
</tbody>
</table>
IMPORTANT: I know one way that works (By.xpath):
driver.findElement(By.xpath("//td[#width='100%']")).getText();
However, this way does not ALWAYS work. The page is dynamic, so I need a way to locate that element no matter what changes happen to the page.
I tried the following but I am not sure:
By.xpath("//html//body//table//tbody//tr[3]//td//table//tbody//tr//td[2]//table[4]//tbody//tr[1]//td//b[3]"
If you can't change the HTML and want to use attributes for selection, you can write something like this:
//table[#border=0][#width=820]//tbody//tr[1]//td//b[3]

Coldfusion : How to include HTML table headers on new page when using cfdocument?

I have a table on a page with data generated from a query. This makes it unpredictable how many rows will be generated.
When using cfdocument to output the page as a PDF the table is often cut in two on the page break.
Is there any easy way to include the table labels on the new page for the purpose of clarity?
I've had to work with cfdocument quite a bit and making it usable in certain situations can be a real bear.
I believe the answer to your question can be found on this page since you know how many records will be on each page (static row height):
COLDFUSION: cfdocument and forcing a pagebreak
Here are some other questions I've posted and worked through concerning cfdocument, hope they help.
scale PDF to single page
cfdocument prevent page breaks mid-row
CFDocument still cutting off the tops of text on some pages
try this approach, I have used it
<cfset amount="6" />
<cfdocument
format="pdf"
unit="cm"
pageType="A4"
filename="#path##name#.pdf">
<cfoutput>
<cfloop from="1" to="#amount#" index="i">
<cfset filename = "#name#_#i#" />
<cfimage
action="convert"
destination="#path#codes/#filename#.jpg"
source="#path#codes/#filename#.png" />
<img src="file://#path#codes/#filename#.jpg" style="width: 3.58cm; margin: 0 0.2cm 0.5cm;">
</cfloop>
</cfoutput>
Just adding some things that DON'T work (in CF10, which i think uses the same CFdoc renderer as CF8 & CF9):
adding content after the header element with css:after (CFdocument doesn't support css3)
thead { display: table-header-group; } (not supported)
using javascript within the table output to add a header row dynamically (the pdf renderer doesn't execute js)
testing #cfdocument.currentpagenumber# in the cfdocument body (that variable seems only to exist in the header and footer)
adding a in the (soundsOfTheDot answered his other question saying that this worked, but in my tests the renderer seems to close the table at the end of each page then re-open it)
adding a table in the with a test like to insert it on all pages after the first one (this almost does the job, if you can hard-code your column widths so the two tables line up and ensure there is no gap between this faux header and the actual table)
I hope that saves some hours.
My PDF happened to fit 21 rows per page, so I made sure the current row MODULO 21 equaled 0. Notice I start with a new table each page, so I put the new <table> along with only a <thead> inside the <cfif> after using the closing tags of </tbody> and </table> for the previous page's table and the pagebreak. Then I follow it with the <tbody>, and voila, it works like a charm. I also added a nice footer to the PDF just for funsies.
<cfquery name="getDeletedBarcodes" datasource="#application.dsn#">
SELECT * FROM deletedRecords
</cfquery>
<cfdocument filename="reports/DeletedBarcodes.pdf" format="PDF" overwrite="true">
<cfif getDeletedBarcodes.RecordCount NEQ 0>
<h2 align="center" style="text-decoration: underline; font-weight: bold">Deleted Barcode Records</h2>
<table class="deletedBarcodesTable" border="1" style="margin-top: 10px" rules="rows">
<thead>
<tr>
<th>Barcode</th>
<th>Building</th>
<th>Room</th>
<th>Location</th>
<th>Shelf</th>
<th>Inventoried</th>
<th>Deleter Name</th>
<th>Time Deleted</th>
<th>Reason Deleted</th>
</tr>
</thead>
<cfelse>
<p>There are no records to show that have deleted barcodes.</p>
</cfif>
<cfloop query="getDeletedBarcodes">
<cfoutput>
<cfif getDeletedBarcodes.currentRow MOD 21 EQ 0>
</tbody></table>
<cfdocumentitem type="pagebreak" />
<table class="deletedBarcodesTable" border="1" style="margin-top: 10px" rules="rows">
<thead>
<tr>
<th>Barcode</th>
<th>Building</th>
<th>Room</th>
<th>Location</th>
<th>Shelf</th>
<th>Inventoried</th>
<th>Deleter Name</th>
<th>Time Deleted</th>
<th>Reason Deleted</th>
</tr>
</thead>
<tbody>
</cfif>
<tr>
<td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "Barcode") OR NOT len(Barcode)><strong style="color: red">N/A</strong><cfelse>#Barcode#</cfif></td>
<td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "Building") OR NOT len(Building)><strong style="color: red">N/A</strong><cfelse>#Building#</cfif></td>
<td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "Room") OR NOT len(Room)><strong style="color: red">N/A</strong><cfelse>#Room#</cfif></td>
<td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "Location") OR NOT len(Location)><strong style="color: red">N/A</strong><cfelse>#Location#</cfif></td>
<td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "Shelf") OR NOT len(Shelf)><strong style="color: red">N/A</strong><cfelse>#Shelf#</cfif></td>
<td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "Inventoried") OR NOT len(Inventoried)><strong style="color: red">N/A</strong><cfelse>#LEFT(Inventoried, 10)#</cfif></td>
<td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "DeleterName") OR NOT len(DeleterName)><strong style="color: red">N/A</strong><cfelse>#DeleterName#</cfif></td>
<td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "TimeDeleted") OR NOT len(TimeDeleted)><strong style="color: red">N/A</strong><cfelse>#TimeDeleted#</cfif></td>
<td align="center"><cfif NOT StructKeyExists(getDeletedBarcodes, "ReasonDeleted") OR NOT len(ReasonDeleted)><strong style="color: red">N/A</strong><cfelse>#ReasonDeleted#</cfif></td>
</tr>
</cfoutput>
</cfloop>
<cfdocumentitem type="footer">
<cfoutput>
<div style="border-top: 5px solid black; border-top-width: 100vw">
<span style="left: 0; float: left">#DateFormat(Now(), "full")#</span>
<span style="right: 0; float: right">Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</span>
</div>
</cfoutput>
</cfdocumentitem>
</cfdocument>

Force a page break and including headers when using cfdocument?

I'm generating a <table> and converting it to PDF using <cfdocument>. I would like to include the table header on the new page when it runs over. This is around every 30th line.
Here is my current code. The <cfif> is supposed to force a break at every new line. However, all it seems to do is create 4 blank pages with the content at the bottom, formatted the same as it was before
<cfloop query="One">
<cfif not(One.currentrow MOD 30)>
<cfdocumentitem type="pagebreak" />
<th>Contact Name</th>
</cfif>
<cfoutput>
#One.contactName#
</cfoutput>
Fixed. Here is what I used to get my header on every page. Further note, if you need to adjust the document header size, then include margintop="2.2" in your main tag and adjust to taste.
<cfdocumentitem type="header" evalAtPrint="true" >
<td>Contact Name</td>
</cfdocumentitem>
Try This: This is the solution that i got.
<cfloop query="get_list">
<!---7 row each page--->
<cfset mode = get_list.currentrow mod 7>
<cfif mode eq 1>
<thead>
<tr>
<td>table header</td>
</tr>
</thead>
</cfif>
<tbody>
<tr>
<td>data loop here</td>
</tr>
<tr>
<td>
<cfif mode eq 0>
<cfdocumentitem type="pagebreak">
</cfdocumentitem>
</cfif>
</td>
</tr>
</tbody>
</cfloop>
</table>