简体   繁体   English

PDF 竖切合并

[英]PDF Cut Vertically and Merge

I have a booklet pdf.我有一本小册子 pdf。 I want to Split in half ie Vertical + Re-paginate from booklet scan我想分成两半,即垂直+从小册子扫描重新分页

Ex: booklet pages would be 1, 8 and 7, 2 etc.,例如:小册子页面将是 1、8 和 7、2 等,

After processing i want to have a PDF with 1, 2, 3, 4, ....处理后我想要一个 PDF 与 1, 2, 3, 4, ....

Please advise which PDF library would be able to do the above in java请告知哪个 PDF 库能够在 java 中执行上述操作

Thanks谢谢

Depending on how the booklet was scanned into the PDF, I think you might be able to do this using a Java library that can extract and merge PDF pages.根据将小册子扫描到 PDF 的方式,我认为您可以使用可以提取和合并 PDF 页面的 Java 库来执行此操作。

For example, in the LEADTOOLS Java PDF Library , which is what I am familiar with since I work for the vendor, there is a PDFFile class that can be used to extract and merge pages from and to a PDF file. For example, in the LEADTOOLS Java PDF Library , which is what I am familiar with since I work for the vendor, there is a PDFFile class that can be used to extract and merge pages from and to a PDF file.

PDFFile file = new PDFFile(bookletFile);
int pageCount = file.getPageCount();
for (int i = 1; i <= pageCount; i++)
{
   File destinationFile =  new File(destinationFolder, String.format("Extracted_Page{0}.pdf", i));
   file.extractPages(i, i, destinationFile.getPath());
}

Since the booklet looks like it's scanned in a way that every other page will contain a double page.由于小册子看起来像是以每隔一页包含双页的方式扫描的。 To split them, you can load every other extracted page as a raster image then use the library's raster imaging classes to save each half as a separate raster PDF:要拆分它们,您可以将每个其他提取的页面加载为光栅图像,然后使用库的光栅成像类将每一半保存为单独的光栅 PDF:

RasterCodecs codecs = new RasterCodecs();
RasterImage firstHalfImage = codecs.load(extractedDoublePage);

// Create a LeadRect that encompasses the second half
LeadRect secondHalfLeadRect = new LeadRect(firstHalfImage.getImageWidth() / 2, 0, firstHalfImage.getImageWidth() / 2, firstHalfImage.getImageHeight());
// Create a new image containing the second half
RasterImage secondHalfImage = firstHalfImage.clone(secondHalfLeadRect);

// Crop First Image to contain only first half
LeadRect firstHalfLeadRect = new LeadRect(0, 0, firstHalfImage.getImageWidth() / 2, firstHalfImage.getImageHeight());
CropCommand cropCommand = new CropCommand(firstHalfLeadRect);
cropCommand.run(firstHalfImage);

You can then use the RasterCodecs.Save() method to save each image as a raster PDF file.然后,您可以使用RasterCodecs.Save()方法将每个图像保存为光栅 PDF 文件。

Finally, once you have split everything accordingly, you can use the PDFFile.MergeWith() method to combine all the pages back into one file in the needed order.最后,一旦您相应地拆分了所有内容,您可以使用PDFFile.MergeWith()方法将所有页面按所需顺序组合回一个文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM