[
https://issues.apache.org/jira/browse/PDFBOX-4614?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16896850#comment-16896850
]
michele valdinoci edited comment on PDFBOX-4614 at 7/31/19 7:22 AM:
--------------------------------------------------------------------
{{importPage}} doesn't use template so output size is bigger (
[^output-importpage.pdf]).
Trying to import 2, 3, 2, 3 sequence, pdf is ok ( [^output-23.pdf])
was (Author: valmic):
{{importPage}} doesn't use template so output size is bigger (
[^output-importpage.pdf]
Trying to import 2, 3, 2, 3 sequence, pdf is ok ( [^output-23.pdf]
> 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-23.pdf, output-importpage.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);
> opdf.addPage(pag1);
> }
> 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();
> 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: [email protected]
For additional commands, e-mail: [email protected]