I am having a problem when merging documents of different widths using iText.
Below is the code that I use to combine.
public static void doMerge(List<InputStream> list, OutputStream outputStream) throws Exception { Rectangle pagesize = new Rectangle(1700f, 20f); com.itextpdf.text.Document document = new com.itextpdf.text.Document(pagesize); PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.open(); document.setPageSize(pagesize); com.itextpdf.text.pdf.PdfContentByte cb = writer.getDirectContent(); for (InputStream in : list){ PdfReader reader = new PdfReader(in); for (int i = 1; i <= reader.getNumberOfPages(); i++){ document.newPage();
The first pdf page will have a width of 14 inches and a height of 13 inches. All other pages in the document will always be smaller.
I want to combine all the documents in one document.
I do not know how to set the width and height of one merged document.
I think Rectangle pagesize = new Rectangle(1700f, 20f); should do it, but it doesn't work if you change it to Rectangle pagesize = new Rectangle(1700f, 200f); , the document has no effect.
I ask you to continue.
Parth source share