我没有给这些问题适当的标题。 :)
我需要如何从现有 PDF 文件中拆分(获取)页面。为此,我正在使用 droidtext。
我的代码是
try {
String path = Environment.getExternalStorageDirectory()
+ "/test123.pdf";
/*Read Existing PDF*/
PdfReader reader = new PdfReader(path);
Document doc = new Document();
doc.open();
File outfile = new File(Environment.getExternalStorageDirectory()
+ "/test_new.pdf");
if (!outfile.exists())
outfile.createNewFile();
FileOutputStream decfos = new FileOutputStream(outfile);
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, decfos);
document.open();
/*Getting First page*/
PdfImportedPage page = writer.getImportedPage(reader, 1);
Image instance = Image.getInstance(page);
document.add(instance);
document.close();
} catch (DocumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我想从“test123.pdf”文件创建一页 pdf。它正在创建新的 PDF。
但问题是在新的 PDF 文件中有白色边框。我怎样才能删除这些空格。 在原始 PDF 中没有这样的白色边框。
编辑
我再次尝试使用以下代码。但它在 copy.addPage(page);
String path = Environment.getExternalStorageDirectory()
+ "/test123.pdf";
PdfReader reader = new PdfReader(path);
PdfImportedPage page;
PdfSmartCopy.PageStamp stamp;
File outfile = new File(Environment.getExternalStorageDirectory()
+ "/test_new.pdf");
Document doc = new Document();
if (!outfile.exists())
outfile.createNewFile();
FileOutputStream decfos = new FileOutputStream(outfile);
PdfSmartCopy copy = new PdfSmartCopy(doc, decfos);
page = copy.getImportedPage(reader, 5);
stamp = copy.createPageStamp(page);
stamp.alterContents();
copy.addPage(page);
最佳答案
我否决了这个问题有两个原因:
- 您没有阅读官方文档。参见 Edit DirectContent of iTextSharp PdfSmartCopy class找出为什么不阅读文档是错误的。
- 我是 iText 的原始开发者,我不赞成使用 DroidText。这不是正式的 iText 版本。我强烈反对使用它:http://lowagie.com/itext2请注意,我住在比利时,根据比利时法律,我对我制作的所有版权拥有精神权利。这包括 iText 2.1.7。
至于您的问题:您正在创建 A4 格式的页面。您向这些页面添加了未知大小的导入页面。如果这些页面也是 A4 尺寸,它们将适合。如果它们的尺寸不同,则不会。它们要么被剪裁,要么会有不必要的边距。
关于android - 使用白色位置的 PDF 文件结果生成新 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12843623/