[
https://issues.apache.org/jira/browse/FOP-2928?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=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
>