Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Carbon Copy birt with Frameset
pcosta
Hello,
I have a certain report (INVOICING) and I get this int var value the number of copies that i'm suppose to do in one print at the time.
I would like to do carbon copies in just ONE print labeling them as "Original" , "Fist copy", and so on. the Original might get more that one page off course !!
Can any of you give me any sort on inspiration to do the job...please.
I would like to avoid java approach, instead java script on the report itself, because all i'm using is the frameset servlet all the time.
Thanks ins advence
Find more posts tagged with
Comments
kclark
I'm working on a javascript example for you that I've almost got working. There's around 100 lines of code so far. I'll post it when I've got it but I think it might be easier to go with java for something like this.
What I'm doing is using parameters to store which copy it is, change the "Copy n of m" label to match, generate the PDF with some JS in a temp location and then redirect the report back to itself to create the next n of m until the parameter equals the number of copies that has been provided in an HTML form.
pcosta
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="113788" data-time="1359668226" data-date="31 January 2013 - 02:37 PM"><p>
I'm working on a javascript example for you that I've almost got working. There's around 100 lines of code so far. I'll post it when I've got it but I think it might be easier to go with java for something like this.<br />
<br />
What I'm doing is using parameters to store which copy it is, change the "Copy n of m" label to match, generate the PDF with some JS in a temp location and then redirect the report back to itself to create the next n of m until the parameter equals the number of copies that has been provided in an HTML form.<br /></p></blockquote>
<br />
Thanks a lot i will wait<br />
Paulo
kclark
Sorry it took a little bit to get this working. I scrapped the last rptdesign I was working on because it was rerunning the dataset each time. I've attached an example for you to take a look at. I downloaded iText and added the jars to the project class path. In the first report I used a text object to ask how many carbon copies the user wants. The report then opens itself in a new window passing the amount of copies through a parameter, generated the original PDF, then I used iText to append that PDF with a "Carbon copy n of m" label at the top. This rptdesign generates a new PDF for each carbon copy, I don't know if you wanted them all in the same file. If that's the case then I believe that iText has a merge() that will allow you to merge all the PDF's into one file.<br />
<br />
Here's the script I wrote to generate the copies<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.com.itextpdf.awt);
importPackage(Packages.com.itextpdf.text.pdf);
importPackage(Packages.com.itextpdf.text);
importPackage(Packages.com.itextpdf.text.pdf.ocg);
importPackage(Packages.java.io);
if(params["dropForm"].value > 0) {
importPackage(Packages.org.eclipse.birt.report.engine.api);
var re = reportContext.getReportRunnable().getReportEngine();
var mydoc = reportContext.getHttpServletRequest().getAttribute("attributeBean").getReportDocumentName();
var mydocument = re.openReportDocument(mydoc);
var options = new PDFRenderOption();
var outputfile = "c:/test/original.pdf";
options.setOutputFileName(outputfile);
options.setOutputFormat("pdf");
ntask = re.createRenderTask(mydocument);
ntask.setRenderOption(options);
ntask.render();
mydocument.close();
ntask.close();
for(i=0;i<=params["carbonNum"].value;i++) {
if(i!=0) {
var result = "c:\\test\\appended.pdf";
reader = new PdfReader("c:\\test\\original.pdf");
stamper = new PdfStamper(reader, new FileOutputStream("c:\\test\\carboncopy" + i + ".pdf"), '\0', true);
cb = stamper.getUnderContent(1);
cb.beginText();
cb.setFontAndSize(BaseFont.createFont(), 12);
cb.showTextAligned(Element.ALIGN_LEFT, "***CARBON COPY #" + i + "***", 36, 770, 0);
cb.endText();
stamper.close();
reader.close();
}
}
}
</pre>
<br />
Let me know if the works for you
pcosta
<blockquote class='ipsBlockquote' data-author="'kclark'" data-cid="113900" data-time="1360001455" data-date="04 February 2013 - 11:10 AM"><p>
Sorry it took a little bit to get this working. I scrapped the last rptdesign I was working on because it was rerunning the dataset each time. I've attached an example for you to take a look at. I downloaded iText and added the jars to the project class path. In the first report I used a text object to ask how many carbon copies the user wants. The report then opens itself in a new window passing the amount of copies through a parameter, generated the original PDF, then I used iText to append that PDF with a "Carbon copy n of m" label at the top. This rptdesign generates a new PDF for each carbon copy, I don't know if you wanted them all in the same file. If that's the case then I believe that iText has a merge() that will allow you to merge all the PDF's into one file.<br />
<br />
Here's the script I wrote to generate the copies<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.com.itextpdf.awt);
importPackage(Packages.com.itextpdf.text.pdf);
importPackage(Packages.com.itextpdf.text);
importPackage(Packages.com.itextpdf.text.pdf.ocg);
importPackage(Packages.java.io);
if(params["dropForm"].value > 0) {
importPackage(Packages.org.eclipse.birt.report.engine.api);
var re = reportContext.getReportRunnable().getReportEngine();
var mydoc = reportContext.getHttpServletRequest().getAttribute("attributeBean").getReportDocumentName();
var mydocument = re.openReportDocument(mydoc);
var options = new PDFRenderOption();
var outputfile = "c:/test/original.pdf";
options.setOutputFileName(outputfile);
options.setOutputFormat("pdf");
ntask = re.createRenderTask(mydocument);
ntask.setRenderOption(options);
ntask.render();
mydocument.close();
ntask.close();
for(i=0;i<=params["carbonNum"].value;i++) {
if(i!=0) {
var result = "c:\\test\\appended.pdf";
reader = new PdfReader("c:\\test\\original.pdf");
stamper = new PdfStamper(reader, new FileOutputStream("c:\\test\\carboncopy" + i + ".pdf"), '\0', true);
cb = stamper.getUnderContent(1);
cb.beginText();
cb.setFontAndSize(BaseFont.createFont(), 12);
cb.showTextAligned(Element.ALIGN_LEFT, "***CARBON COPY #" + i + "***", 36, 770, 0);
cb.endText();
stamper.close();
reader.close();
}
}
}
</pre>
<br />
Let me know if the works for you
<br /></p></blockquote>
<br />
<br />
<br />
Hello kclark, I'km goin to test it.<br />
Thank you very much
kclark
You're welcome, let me know if it needs to be modified at all.