christian siagian
christian siagian

Reputation: 1

PDFsharp Invalid Version PDF File

I created a PDF with PDFsharp and ASP in coding and combined it with the finished PDF file. when I tried to replace the finished PDF file, the error {"Invalid version number. Valid values are 12, 13, and 14.\r\nParameter name: value"} appeared. so the resulting PDF is only the PDF that I created, the finished PDF file was not combined because there was an error.

This is my coding

try
{
     Byte[] howToPay = File.ReadAllBytes(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, howToPayPath));
     PdfDocument HowToPayPdf = PdfReader.Open(new MemoryStream(howToPay), PdfDocumentOpenMode.Import);

     outputPDFDocument.Version = HowToPayPdf.Version;

     foreach (PdfPage page in HowToPayPdf.Pages)
     {
         outputPDFDocument.AddPage(page);
     }
}
catch (Exception ex)
{
     log.ErrorFormat("GenerateInvoice() Add How To Pay - Error : {0}", ex.Message);
}

goes into catch when processing outputPDFDocument.Version = HowToPayPdf.Version;

I just replaced the finished file, and didn't expect an error to appear.

Upvotes: -1

Views: 247

Answers (1)

You are using an old version of PDFsharp. The current version supports values up to 20.

There is no need to set the version of the output PDF because it gets a supported value by default.
Removing that assignment should be enough to get your code working.

Upvotes: 0

Related Questions