Jump to content

BIRT Developer Center Download


Photo
- - - - -

Carbon Copy birt with Frameset


  • Please log in to reply
5 replies to this topic

#1 pcosta

pcosta

    Junior Member

  • Members
  • Pip
  • 8 posts

Posted 31 January 2013 - 01:36 AM

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

#2 kclark

kclark

    Senior Member

  • Administrators
  • 2042 posts

Posted 31 January 2013 - 01:37 PM

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.

Kristopher Clark

Actuate Corporation – The BIRT Company™

http://www.actuate.com | http://birtondemand.com

 

My Blog

Twitter

LinkedIn
Facebook
 


#3 pcosta

pcosta

    Junior Member

  • Members
  • Pip
  • 8 posts

Posted 01 February 2013 - 06:04 AM

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.


Thanks a lot i will wait
Paulo

#4 kclark

kclark

    Senior Member

  • Administrators
  • 2042 posts

Posted 04 February 2013 - 10:10 AM

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.

Here's the script I wrote to generate the copies

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();
    }
  }
}

Let me know if the works for you :)

Attached Files


Kristopher Clark

Actuate Corporation – The BIRT Company™

http://www.actuate.com | http://birtondemand.com

 

My Blog

Twitter

LinkedIn
Facebook
 


#5 pcosta

pcosta

    Junior Member

  • Members
  • Pip
  • 8 posts

Posted 05 February 2013 - 07:21 AM

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.

Here's the script I wrote to generate the copies

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();
    }
  }
}

Let me know if the works for you :)




Hello kclark, I'km goin to test it.
Thank you very much

#6 kclark

kclark

    Senior Member

  • Administrators
  • 2042 posts

Posted 05 February 2013 - 01:30 PM

You're welcome, let me know if it needs to be modified at all.

Kristopher Clark

Actuate Corporation – The BIRT Company™

http://www.actuate.com | http://birtondemand.com

 

My Blog

Twitter

LinkedIn
Facebook