Hi,
we're using the DocumentExporter to get an pdf export from our Grid by using the code below.
Now we combine pdf files by PDFSharp (cause infragistics doesn't support something like that). We already combined more than 10000 pdf files but each time we try to combine a pdf generated by the DocumentExporter the combining fails. It says the compression of the file is different then the standard allows. There is no chance to handle it if the exporter publishes a PDF file. Even if the file is completely empty! So the error is the saving of the pdf file it self. It should be full v.1.4 compatible but it isnt.
Current ugly workaround is to export the grid to excel and let excel save the pdf file -> it works.
But our customer want a more handy solution.
Except the ImageCompression there is no setting we can change. So question is:
How can we set some changes for the exported pdf like
Infragistics.Win.UltraWinGrid.DocumentExport.UltraGridDocumentExporter pdfExporter = new Infragistics.Win.UltraWinGrid.DocumentExport.UltraGridDocumentExporter();
pdfExporter.ExportStarted += ultraGridPDFDocumentExporter1_ExportStarted;
pdfExporter.ExportEnded += ultraGridPDFDocumentExporter1_ExportEnded;
pdfExporter.Margins = new PageMargins(10, 10, 10, 10);
pdfExporter.TargetPaperSize = PageSizes.A4;
pdfExporter.TargetPaperOrientation = PageOrientation.Landscape;
pdfExporter.AutoSize = Infragistics.Win.UltraWinGrid.DocumentExport.AutoSize.None;
pdfExporter.ImageCompressorType = Infragistics.Win.UltraWinGrid.DocumentExport.ImageCompressorType.JPEG;
// Export the grid into the report. This will automatically create a new
ISection section = pdfExporter.Export(this.GridToExport, report);
// Publish the report.
report.Publish(path, FileFormat.PDF);
After long long try and error I found a solution.
Coding follows:
/// <summary>
/// Creates the PDF sharp conform PDF file from infragistics PDF file.
/// THIS IS ONLY A MUST NEED BECAUSE THE PDF OF INFRAGISTICS SAVES ITS CONTENT COMPRESSED BY .NET ALGORITHM.
/// BUT PDFSHARP USES THE JAVA COMPRESSION/DECOMPRESSION ALGORITHM TO READ IT IN -> THIS FAILS WITH AN DECOMPRESSION EXCEPTION!
/// So we read in the pdf by iTextshap and generate a new pdf by it with uncompressed! content. This file can be used by PDFSharp also!
/// </summary>
/// <param name="infragisticsPDF">The infragistics PDF.</param>
/// <returns>System.String.</returns>
private string createPDFSharpConformPDFFileFromInfragisticsPDFFile(string infragisticsPDF)
{
//readin file and create a new doc for it
iTextSharp.text.pdf.PdfReader inputReader = new iTextSharp.text.pdf.PdfReader(infragisticsPDF);
iTextSharp.text.Rectangle newRect = inputReader.GetPageSize(1);
iTextSharp.text.Document doc = new iTextSharp.text.Document(newRect);
doc.SetMargins(0, 0, 0, 0);
iTextSharp.text.Document.Compress = false; //THIS LINE IS IMPORTANT -> RESAVE FILE AS UNCOMPRESSED VERSION!
//set ouput file
var correctedFilePath = Path.Combine(_reportObjectSettings.TemporaryFilePathForSinglePdfFiles, Path.GetFileNameWithoutExtension(infragisticsPDF) + "_uncompressed.pdf");
iTextSharp.text.pdf.PdfWriter outputWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new FileStream(correctedFilePath, FileMode.Create));
outputWriter.SetPdfVersion(iTextSharp.text.pdf.PdfWriter.PDF_VERSION_1_4); //only to get sure!
doc.Open();
//now write/copy each page of it into new doc
iTextSharp.text.pdf.PdfContentByte cb = outputWriter.DirectContent;
for (int pageNumber = 1 ; pageNumber <= inputReader.NumberOfPages ; pageNumber++)
iTextSharp.text.pdf.PdfImportedPage page = outputWriter.GetImportedPage(inputReader, pageNumber);
cb.AddTemplate(page, 0, 0);
doc.NewPage();
}
doc.Close();
doc = null;
return correctedFilePath;
The DotNet compression is done using the DeflateStream class. I don't have any sample code, but I'm sure there must be some in Microsoft's documentation or online somewhere.
Hm ok,
I think you're right. PDFSharp throws an exception after inflating the file. So i think it must be the compression.
Because PDFSharp uses SharpZlib (its adopted from the Java implementation).
That is very unfortunate that the user has no chance to use your generated pdf files in that way.
Did you know the place were I can found some samples using the flate compression and decompression? Maybe I can implement something above PDFSharp that it will you both compression method (first Java and if its fails -> .NET). With that solution our customer can use also your generated pdf files.
Hm, okay, I guess I was wrong about the 1.3 standard. Sorry about the confusion.
The Infragistics documents engine is using the Flate compression functionality in DotNet. The DotNet algorithm is apparently incompatible with the Flate compression used by Java. I'm not sure why, but they simply don't work together. So if compression is the issue, my guess is that PDFSharp is using the Java compressor. I could be wrong, of course, but you could probably check with the makers of PDF Sharp to confirm. If that's the case, there's nothing we can do to fix this.
Hi Mike,
1.3? But inside the properties of the file i can see it is exported as 1.4 ;)
We're using the latest versions of 13.2 ultimate including the service releases.
Sorry but I'm not the expert creating a pdf format but is it possible to check if the error comes within the latest changes?
Eg. using a font that isn't embedded or maybe a normal standard font type?
Is it better to open a service request ticket for that problem?