How to write a new pdf every 4 pages of the main pdf c# Winforms

Asked

Viewed 10 times

-1

I have a pdf document with more than 1000 pages and want to separate it into different pdfs every 4 pages, how can I do this?

public string ReadPdfFileForTreatment2(string fileName)
    {
        StringBuilder text = new StringBuilder();
        Document doc = new Document();
        if (File.Exists(fileName))
        {
            PdfReader pdfReader = new PdfReader(fileName);

            for (pageT1 = 1; pageT1 <= pdfReader.NumberOfPages; pageT1++)
            {
                ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
                string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, pageT1, strategy);

                currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
                text.Append(currentText);


                
                PdfWriter.GetInstance(doc, new FileStream(txbCaminho.Text, FileMode.Create));
                doc.Open();

                Paragraph p = new Paragraph(currentText);
                doc.Add(p);
                doc.Close();

                if (pageT1 == 4)
                {

                }
            }
            pdfReader.Close();
        }
        return text.ToString();
    }

I’m reading page by page, but I don’t know what to do next, thanks for the help. ps: pageT1 is the variable where I am to see on which pdf page I am.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.