Вставьте пустую страницу после каждых 2 страниц в pdf (в java / c #; но не в acrobat) - PullRequest
0 голосов
/ 20 апреля 2020

Я видел 10 или 20 решений на inte rnet, все они показывают решение в acrobat pro, которого у меня нет. Я буду благодарен, чтобы получить хотя бы ссылку или направление к решению.

Спасибо всем.

Приветствия, Модашер.

===================== Обновление :::::::::::::::: Мне удалось создать код, который работает. Но теперь проблема в том, что выходной файл равен 1,8 ГБ, а для исходного файла всего 7,5 МБ. Любой код, который я могу добавить в моей программе для сжатия?

Еще раз спасибо, ребята. Благодарим Вас за помощь.

=========================== *======

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;

namespace ConsoleApplication3
{
class Program
{
    static void DuplexOnly(string[] args)
    {
        PdfReader reader = null;
        Document sourceDocument = null;
        PdfCopy pdfCopyProvider = null;


        try
        {
            // Intialize a new PdfReader instance with the contents of the source Pdf file:
            reader = new PdfReader(@"C:\Users\chakladerm\Desktop\billing - Copy\PDFsam_mergeall.pdf");
            int pageNum = 1;

            sourceDocument = new Document(reader.GetPageSizeWithRotation(reader.GetPageN(1)));
            pdfCopyProvider = new PdfCopy(sourceDocument,
                new System.IO.FileStream(@"C:\Users\chakladerm\Desktop\billing - Copy\PDFsam_mergeall_Duplex.pdf", System.IO.FileMode.Create));
            sourceDocument.Open();

            string AccountNumber = "";
            int pagesInBill = 0;
            while (reader.GetPageN(pageNum) != null)
            {
                pageNum++;
                                    string pageText = PdfTextExtractor.GetTextFromPage(reader, pageNum - 1);
                if (pageText.Contains("Property:") == false && pageText.Contains("Total New Charges") == false)
                {

                    AccountNumber = pageText.Split('Ä')[1].Split('\n')[1].Trim();
                    pdfCopyProvider.AddPage(reader.GetPageSize(1), 1);
                    if (pagesInBill  == 2)
                        pdfCopyProvider.AddPage(reader.GetPageSize(1), 1);

                    pagesInBill = 0;
                }

                pdfCopyProvider.AddPage(pdfCopyProvider.GetImportedPage(reader, pageNum-1));

                pagesInBill++;

            }
                         // Close previous page
            sourceDocument.Close();
            reader.Close();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
            // Splits out specific bills and make it possible to duplex
    static void Main(string[] args)
    {
        PdfReader reader = null;
        Document sourceDocument = null;
        PdfCopy pdfCopyProvider = null;

        DuplexOnly(args);


    }
...