The attached pdf is created by PDFSharp:
string source = filepath_mage; string destinaton = filepath_pdf; using ( PdfDocument doc = new PdfDocument() ) { XImage img = XImage.FromFile(source); PdfPage nxpage = new PdfPage(); doc.Pages.Add(nxpage); XGraphics xgr = XGraphics.FromPdfPage(nxpage); XRect srcRect = new XRect(0,0,img.PixelWidth,img.PixelHeight); XRect dstRect = new XRect(0,0,nxpage.Width.Value,nxpage.Height.Value); xgr.DrawImage(img,dstRect,srcRect,XGraphicsUnit.Point); using ( Stream nxream = File.Open ( destinaton, FileMode.Create ) ) { doc.Save(nxream); } }
It cannot be read by PDFSharp:
PdfDocument inputDocument = PdfReader.Open(file,PdfDocumentOpenMode.Import);
Exception: PdfSharp.Pdf.IO.ObjectNotAvailableException: 'Cannot retrieve stream length. PDFsharp cannot read this PDF file. If you think your file is a valid PDF file please send it to us so that we can fix this bug in the PDF parser.'
|