I am getting a System.IO.IOException “Getting pdf version error” when calling BindPdf on the PdfContentEditor. I have attached the pdf which causes the error. The pdf was generated from SQL Server Reporting Services.
Thank you for considering Aspose.
I am unable to reproduce this error. I have checked with latest version of Aspose.Pdf.Kit. Could you please tell us which version of Aspose.Pdf.Kit you are using. I have used the following code and the resultant output is attached.
PdfContentEditor editor = new PdfContentEditor();
string KitTestPath = @"D:\AsposeTest\";
string KitTestOut = @"D:\AsposeTest\";
System.Drawing.Rectangle rect1 = new System.Drawing.Rectangle(50, 50, 100, 100);
editor.BindPdf(KitTestPath + "reportbundle.pdf");
System.Drawing.Color clr = System.Drawing.Color.FromArgb(255, 255, 0, 10);
editor.CreateRubberStamp(1, rect1, "NotForPublicRelease", "ok!", clr);
editor.Save(KitTestOut + "PdfContentEditor.CreateRubberStamp.out.pdf");
I have recently had exactly the same problem and have found the cause and a workaround.
The issue is with the format of the PDF rendered by the SQL Reporting Services web service, specifically the version comment at the start of the data. According to the Adobe PDF specification the version comment should be of the format :
followed immediately by either a carriage return (0xd) a line feed (0xa) or both (0xd 0xa).
But the format produced by the PDF renderer is of the following format:
followed by a carriage return & line feed. Note the extra % at the end this is what is causing the problem when the PdfContentEditor parses the PDF file.
Whether this is a bug in Reporting Services or in the Aspose PdfContentEditor is a matter for debate since the ‘%’ character in the PDF is a comment delimiter and strictly should be ignored, but the PDF specification does not say explicitly whether tor not the trailing ‘%’ is correct.
Aspose will have to debate this with Microsoft and Adobe!!!
There is however a workaround, the PDF stream/file can be modified directly and the offending ‘%’ character removed prior to calling PdfContentEditor.BindPDF.
Example using the Reporting Services web service:
byte report = service.Render(reportName , <...additional parameters removed...>);
// overwrite the trailing '%'
report = 0x0; // Alternatively can use space (0x20) or zero (0x30) characters
Hope this helps someone.
(This is all using Aspose.Pdf.Kit version 2.6)
Thanks for sharing the information with us. We will investigate the issue in detail and will update you with the status of resolution to this problem.