Please give a brief summary of your issue:
Issue converting files using the internal converter
Please describe your issue and provide steps to reproduce it:
I have created a service that converts documents of a specific file type to PDF with Visual Studio 2022 in C#. For Office documents I use the OfficeToPDF() converter, which works as expected. When I try to convert TIF, JPG or PNG to PDF using the generic ToPdf(pdfdoc, filename, null) converter without any options, this results in the exception:
PackageV2: base
Data at the root level is invalid. Line 1, position 1.
The logic is deployed as an Azure Application service, but the issue is the same when it runs locally from VS.
Maybe I’m missing an assembly or something, but there is no mention of that at compile or at runtime.
There could also be the requirement for the XPS printer driver, but as far as I know I only use the formats that should be able to be converted without the printer driver. I use the Convert.RequiresPrinter() on the input file and this returns False.
Please provide a link to a minimal sample where the issue is reproducible:
Hello, I’m AiRon, an automated tech support bot While you wait for one of our customer support representatives, I can help you with your question.
The error message “Data at the root level is invalid” typically indicates an issue with the input file format or the way the file is being read. In the context of the PDFNet SDK, this could be related to how the image files (TIF, JPG, or PNG) are being processed or passed to the conversion function.
Some things you can try:
Ensure that the image files are being read correctly before being passed to the ToPdf function. Verify that the files are not corrupted or empty.
Check if the file paths are correct and accessible from the location where the application is running.
Consider using the pdftron.PDF.Image.Create method to create an image object from the file and then add it to the PDF document manually.
Verify that all necessary assemblies are referenced in your project, especially those related to image processing.
If running in Azure, ensure that the environment has all the necessary configurations and permissions to access and read the files.
Hi Robert,
My name is Christopher, and I am a Support Engineer with the Apryse SDK. First, thank you for all of the information. I will need to test this on my end to try to replicate what you are seeing. I would recommend downloading the latest version of the Apryse toolkit, v11.6, in the meantime to see if that might resolve the issue. If that does resolve the issue, please let me know. Once I have run some tests on my end I will reach back out.
Hi Robert,
I have not been able to replicate the issue that you are seeing on my end. Below is an example of how I am calling this in my sample application. This output as a PDF without issue. Can you show me how you are calling this in your code so that I might better understand how to replicate what you are seeing?
using (PDFDoc pdfdoc = new PDFDoc())
{
pdftron.PDF.Convert.ToPdf(pdfdoc, inputPath);
pdfdoc.Save(outputPath, SDFDoc.SaveOptions.e_remove_unused);
Console.WriteLine(“test file saved”);
}
I have updated the software (copied the new version over the old version), with the same result. I have tried with several files (tif, jpg, png). Your AI colleague replied that I might be missing some dependency. Maybe the problem lays there, but I don’t know which dependency I would be missing.
The code looks the same as far as I can see. I use the following code (the PDFTronConvert is just an alias for pdftron.PDF.Convert):
private void ConvertImageDocumentToPDF(string input_file, string output_file)
{
// perform the conversion with no optional parameters
if (!PDFTronConvert.RequiresPrinter(input_file))
{
using (PDFDoc pdfdoc = new PDFDoc())
{
PDFTronConvert.ToPdf(pdfdoc, input_file, null);
// save the result
pdfdoc.Save(output_file, SDFDoc.SaveOptions.e_remove_unused);
}
}
else
{
// _logger.LogError($"{input_file} requires the printer");
throw new Exception($"{input_file} requires the printer");
}
}
Looking over your code, the main thing I notice that stands out as a potential issue is theToPDF() call.
The ToPDF() function has multiple overloads that take in different parameters so passing null as the third parameter could be causing some issues. Could you try updating the call to:
PDFTronConvert.ToPdf(pdfdoc, input_file);
Here is a link to the documentation in case you’d like to explore the other overloads and options available.