0

I want to read the contents of my pdf file into another pdf file using pdfsharp, here is my code below, i just wanted to read the contents either in the form of bytes or in string format, but by using pdfsharp.

public static void Main()
{
    PdfDocument pdf = PdfReader.Open(@"C:\backup_temp\Template.pdf");
    string outputText= "";

    foreach (PdfPage page in pdf.Pages)
    {
        for (int index = 0; index < page.Contents.Elements.Count; index++)
        {
            PdfDictionary.PdfStream stream = Page.Contents.Elements.GetDictionary(index).Stream;
            outputText += new PDFParser().ExtractTextFromPDFBytes(stream.Value);
         }
     }

     string pdfFilename = @"C:\backup_temp\source.pdf";
     pdf.Save(pdfFilename);
 } 
Filburt
  • 17,626
  • 12
  • 64
  • 115
Shakti S
  • 21
  • 10
  • Read the comments of the question [creating new pdf by copying data from another pdf](https://stackoverflow.com/questions/45415907/creating-new-pdf-by-copying-data-from-another-pdf) to find out why no tool can do what you want. – Bruno Lowagie Aug 02 '17 at 12:06
  • fine those are completely different from what i am asking, okay, is there anyother thing in which i have to read a content from a pdf and edit something in it and save it in a new file? i mean according to your answers it is not possible with itextsharp , or pdfsharp sharp right? then is there any other way , but it has to be done using c#, please suggest me...i heared that there is something called "cutepdf" and using that i can meet my requirements, i am going through it..so i need some help ..is there anyother way like this.. – Shakti S Aug 03 '17 at 06:02
  • Cutepdf is an editor with a GUI where you manually (and visually) change content. You are asking for a C# library in which you can treat PDF as if it were a *word processing* format (which it isn't). The fact that you don't get an answer to your question, should make you reconsider. Ask yourself: is there an answer to my question? (Hint: the answer is: no, there isn't.) – Bruno Lowagie Aug 03 '17 at 06:26
  • so there is no possible way to edit the pdf using c# , either it can be edited in word and then it can be changed into pdf using docx, i am just making it conform. – Shakti S Aug 03 '17 at 07:29
  • I repeat: If you want to change a PDF, don't try to edit the PDF, instead edit the source that was used to create the PDF, then convert that source to PDF. For instance: a PDF contains a subset of a special font. You introduce new text that contains a character that is not part of the subset of that font. That is problematic: you may not have access to the full font, which means you won't be able to introduce that new character using the same font. The resulting PDF will be ugly as a result. – Bruno Lowagie Aug 03 '17 at 07:34
  • Thankyou Bruno Lowagie... – Shakti S Aug 03 '17 at 07:37

0 Answers0