我正在尝试制作一个巨大的 PDF,它将在一页上包含所有信息,因为文档中的信息之间不能有中断。它可能永远不会被打印,所以 PDF 的大小不是问题。使用 Itext 我发现可能的唯一方法是创建一个 14400 像素长的页面“或在 A4 页面中为 5M 的页面,但是如果文档比预期的短,这会留下一个尾随空白(我从来没有看到文档长于 14400 像素) )这是我到目前为止的代码
private void pdfSave() {
float pageWidth = 200f;
float pageHeight = 1440f;
Rectangle pageSize = new Rectangle(pageWidth, pageHeight);
Document mDoc =new Document(pageSize);
String mFileName = new SimpleDateFormat("ddMMyyyy_HHmmss",
Locale.getDefault()).format(System.currentTimeMillis());
String mFilePath = Environment.getExternalStorageDirectory()+"/"+"pdf_viewer"+"/"+mFileName+".pdf";
File dir = new File(mFilePath);
if(!dir.exists()){
dir.getParentFile().mkdir();
}
try{
PdfWriter.getInstance(mDoc, new FileOutputStream(mFilePath));
mDoc.setMargins(10,10,10,10);
mDoc.open();
String mText = mTextEt.getText().toString();
mDoc.add(new Paragraph(mText,FontFactory.getFont(FontFactory.HELVETICA, 4, Font.BOLDITALIC)));
mDoc.close();
}
编辑:我已经尝试使用一个裁剪框和第二遍,如评论中所述,但是如果我调试它,我的应用程序会在这一行崩溃
Rectangle rect = getOutputPageSize(pageSize, reader, i);