Product:
PDFTron.NETCore.Windows.x64
Product Version:
10.10.0
Please give a brief summary of your issue:
PdfTron is misidentifying office types in conversion to Pdf
Please describe your issue and provide steps to reproduce it:
We are attempting to use PdfTron to convert Microsoft Office documents to PDF. These documents are coming as Streams so we are using OfficeToPDF(PDFDoc inDoc, Filter inData, ConversionOptions options). This works for new Office types (DOCX, XLSX,PPTX), but it is misidentifying older formats (DOC, XLS, PPT, RTF) a lot and uses the wrong conversion method. Any help with our issue would be appreciated!
This is the exception we see for these documents:
{“Exception: \n\t Message: document layout failed: Unable to convert this document from binary to OOXML form. File is not a valid zip archive.\n\t Conditional expression: \n\t Version : 10.10.0-4950f2eb9c\n\t Platform : Windows\n\t Architecture : AMD64\n\t Filename : FlowToPDFConversion.cpp\n\t Function : PDF::DocxConversion::Convert()\n\t Linenumber : 200\n”}
Please provide a link to a minimal sample where the issue is reproducible:
This is how we are converting the Stream to use the OfficeToPdf method:
using(pdftron.PDF.PDFDoc pdfDoc = new())
{
using (Filter filter = getFilterForConversion(inpStream))
{
pdftron.PDF.Convert.OfficeToPDF(pdfDoc, filter, null);
pdfDoc.Save(outpMemoryStream, pdftron.SDF.SDFDoc.SaveOptions.e_linearized);
}
}
private static Filter getFilterForConversion(Stream inpStream)
{
using(BinaryReader binaryReader = new(inpStream))
{
// Write stream to a byte array. This is needed for pdfTron.Filters.FilterWriter
int streamLength = (int)inpStream.Length;
Byte[] byteArrayOfStream = binaryReader.ReadBytes(streamLength);
Filter filter = new MemoryFilter(byteArrayOfStream.Length, true);
filter.Begin();
// Write the byte array to the Filter via FilterWriter
using (FilterWriter filterWriter = new FilterWriter(filter))
{
filterWriter.WriteBuffer(byteArrayOfStream);
filterWriter.Flush();
}
// Ensure filter position is at start and return
filter.Begin();
return filter;
}
}