Error merging two PDF files using PDFsharp

Your one is an empty PdfDocument, your two is an empty PdfDocument, the for loop does nothing, and outPdf is an empty PdfDocument.

As always, the computer does what you tell him to do. You can easily see that if you step through your code in a Debugger.

You have to use something like PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import); to open a PDF file for import.

See also: http://www.pdfsharp.net/wiki/ConcatenateDocuments-sample.ashx

new PdfDocument("1.pdf"); does not open/read a file, it just prepares the creation of a new file with that name.


Comments

  1. Greyson

    • 2020/11/13

    Your one is an empty PdfDocument, your two is an empty PdfDocument, the for loop does nothing, and outPdf is an empty PdfDocument.

  2. Boone

    • 2015/10/4

    c# - Error merging two PDF files using PDFsharp - Stack Overflow. I am getting a problem when merging two files. If I try to have the AddPage(from.Pages[i]); in a separate void function I get An object reference is required for the non-static field, method, or. Stack Overflow.

  3. Kenny

    • 2020/9/26

    I am trying to combine multiple PDFs into a single PDF. foreach (PdfPage page in inputDocument.Pages) { outputDocument.

  4. Landyn

    • 2019/10/28

    Multiple single/multi page PDF files should be merged into one multi page PDF file. Solution. The Pdfsharp library allows you to do many different operations on PDF files. As it is a .NET library you can use it without any issues within Powershell. In the attached cO.Pdfsharp.zip you will find a psm1 file and the PdfSharp-gdi.dll in version 1.5

  5. Kohen

    • 2017/6/17

    In this post, we will learn about how to generate a single pdf file from multiple pdf files using PdfSharp library in c#.

  6. Allen

    • 2019/7/27

    I am using PDFSharp to merge multiple PDF documents saved on temp and network locations to then print them as one single task. But it has come to my attention that when a PDF has some notes added to it that they become lost after the merge. I am using the following Method's to merge the PDF's. (input is a list with file locations.) public string CombinePdf (List<string> files) { PdfDocument outDoc = new PdfDocument (); foreach (string file in files) { using (PdfDocument pdfDocument =

  7. Demetrius

    • 2018/2/11

    Merge%20PDF%20Files. Please help me with this issue. DanielMitchell January 28, 2019, 5:50pm #2. It looks like your pdf sharp package is 

  8. Sergio

    • 2016/2/24

    If all you need to do is combine PDFs the UiPath 2.0.0 pdf activities has the Join PDF Files activity that can do that. 1 Like mrice1982 June 12, 2019, 7:58pm

  9. Kamari

    • 2016/5/11

    After many prototypes I settled with PDFsharp in a preview version. Here is a minimalistic example you can use to combine PDF files:.

  10. Elisha

    • 2017/1/24

    I made some file merging using PDFsharp before, and now I'm trying to change several files (insert or remove some pages) and I faced with problem, that the library does not see pages. It says that PageCount == 0 and I cannot find pages in object (while debugging). And sure, I cannot do my current work. I use this very simple code:

  11. Pedro

    • 2015/4/13

    Merge Multiple PDF Files Into Single PDF Using Itextsharp in C# . Error messages are delivered to orchestrations or send ports that have subscribed to 

  12. Turner

    • 2019/2/22

    I am trying to add two pages in one document. These two pages are generated from HTML. Info : HTML Renderer for PDF using PDFsharp, HtmlRenderer.PdfSharp 1.5.0.6 var config = new

  13. Hank

    • 2017/6/30

    how to merge multiple pdf files into one pdf using c# Merge PDF Files with New Method in C# - E- lesson number 2: configure and handle error reports.

  14. Rodrigo

    • 2021/5/30

    Merge-Pdf cmdlet joins all the pages of provided pdf files into one pdf. Merge-Pdf -OutputPath c:\output\out.pdf -Path c:\input\in.pdf -Append

  15. Remington

    • 2020/11/13

    PDF Merger & Splitter is a free, UWP app that uses the open-source PDFsharp library for creating PDF files, though you can only find that out by 

Comments are closed.

Recent Posts