I am using PDFsharp version 1.50.4740.0 (copyrighted 2005-2017 in the DLL file).
The simple C# code below is supposed to load a PDF, copy it (one page at a time), and save the result. It has worked well in the past; I use a more complex version to shorten PDFs by removing some pages.
However, with one particular PDF file (attached), it fails with an assertion failure, saying "Should not come here". You can see the error text screenshotted here (it's very long and I don't know how to copy text from that message box):
https://github.com/empira/PDFsharp/issues/152Does this assertion failure indicate a bug in PDFsharp?
What is the real problem and how can I resolve it? Thanks.
Code:
using System;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
namespace PdfTest
{
static class Program
{
[STAThread]
static void Main()
{
string inFile = @"C:\Users\home\Desktop\2304.pdf";
string outFile = @"C:\Users\home\Desktop\output.pdf";
int start = 1, end = 2; // we know it has exactly 2 pages
using (PdfDocument src = PdfReader.Open(inFile, PdfDocumentOpenMode.Import))
{
using (PdfDocument dst = new PdfDocument())
{
for (int i = start; i <= end; i++)
{
dst.Pages.Add(src.Pages[i - 1]);
}
dst.Save(outFile);
}
}
}
}
}