You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "Brian Scott (Jira)" <ji...@apache.org> on 2021/08/03 16:34:00 UTC
[jira] [Comment Edited] (FOP-2928) PDFDocumentGraphics2D does not
clear content on nextPage()
[ https://issues.apache.org/jira/browse/FOP-2928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17392404#comment-17392404 ]
Brian Scott edited comment on FOP-2928 at 8/3/21, 4:33 PM:
-----------------------------------------------------------
This code works with FOP 1.1, but creates duplicated text with FOP 2.5
Page two should only have 1 line of text, but has two. Page 20 has all the text printed on previous pages.
{{package test;
import java.awt.geom.AffineTransform;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import org.apache.fop.pdf.PDFInfo;
import org.apache.fop.svg.PDFDocumentGraphics2D;
public class TestPDF {
static int DPIscale=4;
static public final int PT=72;
static public int inch(double p) {
return (int)(p*PT*DPIscale);
}
public static void main(String[] args) {
try {
FileOutputStream os=new FileOutputStream("test.pdf");
AffineTransform tx=new AffineTransform();
PDFDocumentGraphics2D gPDF=new PDFDocumentGraphics2D(false);
gPDF.setupDocument(os, (int)(inch(11)/DPIscale), (int)(inch(8.5)/DPIscale));
gPDF.setDeviceDPI(PT);
gPDF.setupDefaultFontInfo();
PDFInfo info= gPDF.getPDFDocument().getInfo();
info.setProducer("from TestPDF");
info.setCreationDate(new Date(System.currentTimeMillis()));
gPDF.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
tx.scale(1.0/DPIscale, 1.0/DPIscale);
gPDF.setTransform(tx);
for (int i = 0; i < 20; i++) {
gPDF.drawString("Page "+i, inch(1), inch(1+i*0.2));
gPDF.nextPage();
}
gPDF.finish();
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}}
was (Author: brianorca):
This code works with FOP 1.1, but creates duplicated text with FOP 2.5
{{package test;
import java.awt.geom.AffineTransform;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import org.apache.fop.pdf.PDFInfo;
import org.apache.fop.svg.PDFDocumentGraphics2D;
public class TestPDF {
static int DPIscale=4;
static public final int PT=72;
static public int inch(double p) {
return (int)(p*PT*DPIscale);
}
public static void main(String[] args) {
try {
FileOutputStream os=new FileOutputStream("test.pdf");
AffineTransform tx=new AffineTransform();
PDFDocumentGraphics2D gPDF=new PDFDocumentGraphics2D(false);
gPDF.setupDocument(os, (int)(inch(11)/DPIscale), (int)(inch(8.5)/DPIscale));
gPDF.setDeviceDPI(PT);
gPDF.setupDefaultFontInfo();
PDFInfo info= gPDF.getPDFDocument().getInfo();
info.setProducer("from TestPDF");
info.setCreationDate(new Date(System.currentTimeMillis()));
gPDF.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
tx.scale(1.0/DPIscale, 1.0/DPIscale);
gPDF.setTransform(tx);
for (int i = 0; i < 20; i++) {
gPDF.drawString("Page "+i, inch(1), inch(1+i*0.2));
gPDF.nextPage();
}
gPDF.finish();
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}}
> PDFDocumentGraphics2D does not clear content on nextPage()
> ----------------------------------------------------------
>
> Key: FOP-2928
> URL: https://issues.apache.org/jira/browse/FOP-2928
> Project: FOP
> Issue Type: Bug
> Components: renderer/pdf
> Affects Versions: 2.2, 2.4
> Reporter: Jürgen Ebert
> Priority: Major
> Labels: easyfix
>
> When switching to a new page using PDFDocumentGraphics2D#nextPage() the current content is added to the PDF document but it is not cleared. Therefore the same content will be repeated on the next page.
> nextPage() calls closePage() which adds this.getString() to the PDFStream.
> this.getString() simply returns the content of currentStream, a StringWriter. The content of currentStream is never cleared and the reference is never set to null. Therefore it will be appended to and it will be added again when the next nextPage() or closePage() or therefore finish() is called.
> A work-arround is to manually set the value of currentStream to null using reflection.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)