Hi,

I am creating a PDF document from a huge XML file, using a SAX parser to read 
it. I need to write to different pages simultaneously, so I'm using templates, 
and, later, I go creating newPage() and setting the right template for every 
page.

The code works well, even when the order of the pages in the final PDF is 
different from the order I create the templates (because I'm setting the 
templates in the right order in the final PDF).
 
The problem arises when the PDF must be structured. I have experience in 
marking 
content and tagging a PDF document during creation, and I think it doesn't work 
well when using templates.
 
The code below shows a reduced example. If you open the resulting PDF, only 
elements from the first page are correctly tagged.
 
 
Document oDoc = new Document();
Rectangle oPageSize = new Rectangle(PageSize.A4);
oDoc.setPageSize(oPageSize);
try {
  PdfWriter oWriter = PdfWriter.getInstance(
    oDoc,
    new FileOutputStream("D:\\Temp\\ITextTemplates.pdf")
  );
  oWriter.setTagged();
  oDoc.open();

  PdfStructureTreeRoot oTagParaRoot = oWriter.getStructureTreeRoot();
  oTagParaRoot.put(PdfName.LANG, new PdfString("es-ES"));
  PdfStructureElement oTagDocumento = new PdfStructureElement(oTagParaRoot, new 
PdfName("Documento"));
  oTagParaRoot.mapRole(new PdfName("Documento"), PdfName.DOCUMENT);
  oTagDocumento.put(PdfName.LANG, new PdfString("es-ES"));

  PdfContentByte oCb = oWriter.getDirectContent();
  BaseFont oFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, 
false);
  oCb.setLeading(16);
  oCb.setFontAndSize(oFont, 12);

  PdfStructureElement oTagParrafoHolaMundo = new 
PdfStructureElement(oTagDocumento, PdfName.P);
  oTagParrafoHolaMundo.put(PdfName.T, new PdfString("Título del tag para el 
párrafo"));
 
  PdfTemplate oT1 = oCb.createTemplate(oPageSize.getWidth(), 
oPageSize.getHeight());
  PdfTemplate oT2 = oCb.createTemplate(oPageSize.getWidth(), 
oPageSize.getHeight());
 
  oT1.setLeading(16);
  oT1.setFontAndSize(oFont, 12);
  oT1.beginMarkedContentSequence(oTagParrafoHolaMundo);
  oT1.beginText();
  oT1.moveText(35, 800);
  oT1.newlineShowText("Hello, World (Template oT1)");
  oT1.newlineShowText("Hello, World");
  oT1.endText();
  oT1.endMarkedContentSequence();
 
  oT2.setLeading(16);
  oT2.setFontAndSize(oFont, 12);
  oT2.beginMarkedContentSequence(oTagParrafoHolaMundo);
  oT2.beginText();
  oT2.moveText(35, 800);
  oT2.newlineShowText("Hello, World (Template oT2)");
  oT2.newlineShowText("Hello, World");
  oT2.endText();
  oT2.endMarkedContentSequence();
    
  oCb.addTemplate(oT1, 0, 0);
  oDoc.newPage();
  oCb.addTemplate(oT2, 0,0);

} catch (Exception ex) {
  ex.printStackTrace();
}
oDoc.close();

 
Any suggestion would be appreciate.
 
Thanks,
 
 
Javier 


      
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to