You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2019/07/30 17:31:00 UTC
[jira] [Commented] (PDFBOX-4614) Duplicated text content in
template
[ https://issues.apache.org/jira/browse/PDFBOX-4614?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16896349#comment-16896349 ]
Tilman Hausherr commented on PDFBOX-4614:
-----------------------------------------
You are using {{addPage()}} on the original pages 0, 1, 0, 1. Thus you are adding content streams twice because no copies are created. (This would be the case if you used {{importPage}} but you don't because {{addPage}} is true.
> Duplicated text content in template
> -----------------------------------
>
> Key: PDFBOX-4614
> URL: https://issues.apache.org/jira/browse/PDFBOX-4614
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.16
> Reporter: michele valdinoci
> Priority: Major
> Attachments: input.pdf, output.pdf
>
>
> I'm trying to create a pdf, starting from another on, using "template" techinque to optimize output size when pages is repeated. I will print text values with PDPageContentStream for each page. From the second import of first page, all written texts are duplicated also in page 1!
> In this sample I compose pdf with input page in sequence: 1, 2, 1 finally 2 (view attached output.pdf). First and third output page have same texts ("page 1" and "page 3"!):
>
> {code:java}
> boolean addPage = true;
> PDDocument ipdf = PDDocument.load(new File("input.pdf"));
> PDDocument opdf = new PDDocument();
> PDPage pag1 = null;
> COSDictionary dic1 = null;
> if (addPage)
> {
> dic1 = new COSDictionary(ipdf.getPage(0).getCOSObject());
> pag1 = new PDPage(dic1);
> System.out.println(pag1.getArtBox().toString());
> System.out.println(pag1.getBBox().toString());
> }
> else
> {
> pag1 = opdf.importPage(ipdf.getPage(0));
> }
> // STREAM 1
> PDPageContentStream stream = new PDPageContentStream(opdf, pag1, AppendMode.APPEND, true, true);
> stream.setNonStrokingColor(Color.BLUE);
> stream.beginText();
> stream.setFont(PDType1Font.HELVETICA, 15f);
> stream.newLineAtOffset(10, 780);
> stream.showText("pag 1");
> stream.endText();
> stream.close();
> opdf.addPage(pag1);
> PDPage pag2;
> if (addPage)
> {
> COSDictionary dic2 = new COSDictionary(ipdf.getPage(1).getCOSObject());
> pag2 = new PDPage(dic2);
> opdf.addPage(pag2);
> }
> else
> {
> pag2 = opdf.importPage(ipdf.getPage(1));
> }
> // STREAM 2
> PDPageContentStream stream2 = new PDPageContentStream(opdf, pag2, AppendMode.APPEND, true, true);
> stream2.setNonStrokingColor(Color.BLUE);
> stream2.beginText();
> stream2.setFont(PDType1Font.HELVETICA, 15f);
> stream2.newLineAtOffset(10, 760);
> stream2.showText("pag 2");
> stream2.endText();
> stream2.close();
> PDPage pag3;
> COSDictionary dic3;
> if (addPage)
> {
> dic3 = new COSDictionary(ipdf.getPage(0).getCOSObject());
> pag3 = new PDPage(dic3);
> opdf.addPage(pag3);
> }
> else
> {
> pag3 = opdf.importPage(ipdf.getPage(0));
> }
> // STREAM 3
> PDPageContentStream stream3 = new PDPageContentStream(opdf, pag3, AppendMode.APPEND, true, true);
> stream3.setNonStrokingColor(Color.BLUE);
> stream3.beginText();
> stream3.setFont(PDType1Font.HELVETICA, 15f);
> stream3.newLineAtOffset(10, 730);
> stream3.showText("pag 3");
> stream3.endText();
> stream3.close();
> PDPage pag4;
> if (addPage)
> {
> COSDictionary dic4 = new COSDictionary(ipdf.getPage(1).getCOSObject());
> pag4 = new PDPage(dic4);
> opdf.addPage(pag4);
> }
> else
> {
> pag4 = opdf.importPage(ipdf.getPage(1));
> }
> // STREAM 4
> PDPageContentStream stream4 = new PDPageContentStream(opdf, pag4, AppendMode.APPEND, true, true);
> stream4.setNonStrokingColor(Color.BLUE);
> stream4.beginText();
> stream4.setFont(PDType1Font.HELVETICA, 15f);
> stream4.newLineAtOffset(10, 730);
> stream4.showText("pag 4");
> stream4.endText();
> stream4.close();
> opdf.save("out.pdf");
> ipdf.close();
> opdf.close();{code}
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org