itext pdf PageSize.LEGAL_LANDSCAPE.rotate() 不打印
itext pdf PageSize.LEGAL_LANDSCAPE.rotate() does not print
我创建了一个程序来编写具有两页的 pdf,第一页是纵向的,第二页是横向的。它创建 pdf,但是当我打印该文件时,它不打印第二页,即横向页面。
下面是我的代码
/******************/
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
public class TestPDF {
public static void main(String args[]) throws DocumentException, FileNotFoundException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("/home/devang/test.pdf"));
document.setMargins(10.0f, 10.0f, 20.0f, 2.0f);
document.open();
//PAGE1
addFirstPage(document);
//PAGE2
addSecondPage(document);
document.close();
}
public static Document addFirstPage(Document document) throws DocumentException {
document.addTitle("Test PDF");
Paragraph paragraph = new Paragraph();
paragraph.setAlignment(Element.ALIGN_CENTER);
paragraph.add("Page 1");
paragraph.add("\nPage 1");
paragraph.add("\nPage 1");
paragraph.add("\nPage 1");
paragraph.add("\nPage 1");
document.add(paragraph);
return document;
}
public static Document addSecondPage(Document document) throws DocumentException {
document.setPageSize(PageSize.LEGAL_LANDSCAPE.rotate());
document.newPage();
document.addTitle("Test PDF");
Paragraph paragraph = new Paragraph();
paragraph.setAlignment(Element.ALIGN_CENTER);
paragraph.add("Page 2");
paragraph.add("\nPage 2");
paragraph.add("\nPage 2");
paragraph.add("\nPage 2");
paragraph.add("\nPage 2");
document.add(paragraph);
return document;
}
}
提前致谢。
将您的代码替换为:
Rectangle a4 = PageSize.A4;
Rectangle a4Landscape = a4.rotate();
document.setPageSize(a4Landscape);
我创建了一个程序来编写具有两页的 pdf,第一页是纵向的,第二页是横向的。它创建 pdf,但是当我打印该文件时,它不打印第二页,即横向页面。
下面是我的代码
/******************/
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
public class TestPDF {
public static void main(String args[]) throws DocumentException, FileNotFoundException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("/home/devang/test.pdf"));
document.setMargins(10.0f, 10.0f, 20.0f, 2.0f);
document.open();
//PAGE1
addFirstPage(document);
//PAGE2
addSecondPage(document);
document.close();
}
public static Document addFirstPage(Document document) throws DocumentException {
document.addTitle("Test PDF");
Paragraph paragraph = new Paragraph();
paragraph.setAlignment(Element.ALIGN_CENTER);
paragraph.add("Page 1");
paragraph.add("\nPage 1");
paragraph.add("\nPage 1");
paragraph.add("\nPage 1");
paragraph.add("\nPage 1");
document.add(paragraph);
return document;
}
public static Document addSecondPage(Document document) throws DocumentException {
document.setPageSize(PageSize.LEGAL_LANDSCAPE.rotate());
document.newPage();
document.addTitle("Test PDF");
Paragraph paragraph = new Paragraph();
paragraph.setAlignment(Element.ALIGN_CENTER);
paragraph.add("Page 2");
paragraph.add("\nPage 2");
paragraph.add("\nPage 2");
paragraph.add("\nPage 2");
paragraph.add("\nPage 2");
document.add(paragraph);
return document;
}
}
提前致谢。
将您的代码替换为:
Rectangle a4 = PageSize.A4;
Rectangle a4Landscape = a4.rotate();
document.setPageSize(a4Landscape);