What to do when a page gets converted to an image

Hello.

I have a PDF file and, when I convert it to XOD, one of its pages gets converted into an image (an image gets added on top of the page content, if you inspect the XAML inside the XOD file, to be precise).
The quality is not so good though.
I know I can increase the DPI setting and make it look better as an image, but that may increase the file size.

Questions:

  1. Is there any way to adjust the threshold that makes the converter decide when to convert to an image?
  2. I guess this conversion to image is being done to improve performance for mobile devices, right?

Thanks. :slight_smile:

  1. I guess this conversion to image is being done to improve performance for mobile devices, right?

Yes, this is correct. By default XOD generation is “flattening” vector content that it deems to be too complex. If not done, then viewing these pages can be very slow on low end mobile devices.

  1. Is there any way to adjust the threshold that makes the converter decide when to convert to an image?

Be default ToXod is operating in “Fast” mode. You can turn it off with the following line.

xodOutputOptions.SetFlattenContent(Convert.FlattenFlag.e_off);

There is a threshold option also, but that is just for text that is clipped, and not for general vector/pattern operations. The heuristics we use internally are both complex, and often changing, so exposing an API to control this in any meaningful way is not really possible or useful.

The better option is to find out what the maximum mega pixel count your lowest end target device is, and set Convert.XODOutputOptions.SetMaximumImagePixels to that.
Then, determine what is the highest zoom factor your WebViewer interface allows, say 400%, and then calculate a DPI for that. PDF files are 72 DPI, while XOD/XPS files are 96 DPI, so in this case you would do 4.072 or 4.096, to get a DPI value.
Convert.XPSOutputCommonOptions.SetDPI

PDFNet will flatten content to that target DPI, which should still look great at maximum zoom, and PDFNet will create image stripes to stay under the max image pixel count.

This will increase the size of the XOD files though.

Thank you for your answer. :slight_smile:

I send you the file that caused my issues, just for you to check if you can improve your conversion.
It is page number 4 that gets converted to an image.
It is very similar to the rest of the pages, so it is not clear at all to me why the SDK decides to turn that particular page into an image and not the rest.

If you find anything interesting, I will be glad to hear about it. :slight_smile:

Also, another problem or weird issue is that some of the images from the PDF become solid gray in the XOD when using:

options.SetFlattenContent(Convert.FlattenFlag.e_off);

For the moment, using:

options.SetDPI(360);
options.SetFlattenContent(Convert.FlattenFlag.e_fast);

..instead of :

options.SetFlattenContent(Convert.FlattenFlag.e_off);

....seems to fix the problem, but maybe you can have a look at this too.
I am attaching the original PDF and a problematic XOD (renamed to have a .XPS extension) generated by this code:

var flatten = false;
var options = new Convert.XODOutputOptions();
options.SetJPGQuality(95); //1 to 100
options.SetMaximumImagePixels(20000000);
if (flatten)
{
    options.SetDPI(360);
    options.SetFlattenContent(Convert.FlattenFlag.e_fast);
}
else
{
    options.SetFlattenContent(Convert.FlattenFlag.e_off);
}
options.SetAnnotationOutput(Convert.XODOutputOptions.AnnotationOutputFlag.e_flatten);
Convert.ToXod(dir + "999.pdf", outFile, options);

Best Regards,

Kostas

999.xps (1.85 MB)

999.pdf (1.92 MB)

While we look into this, can you let me know what version of PDFNet you are using?

I am using version 6.7.1.59452. :slight_smile:

Τη Σάββατο, 8 Ιουλίου 2017 - 2:48:28 π.μ. UTC+3, ο χρήστης Ryan έγραψε:

While we look into this, can you let me know what version of PDFNet you are using?

Hello there! :slight_smile:

Do you have any new finds on this one?
Are there any possibilities for improvement in your SDK?
At least, have you managed to reproduce the issues?

Thanks.

Τη Δευτέρα, 10 Ιουλίου 2017 - 7:33:52 μ.μ. UTC+3, ο χρήστης Give Us A Freaking Break έγραψε:

I am using version 6.7.1.59452. :slight_smile:

Τη Σάββατο, 8 Ιουλίου 2017 - 2:48:28 π.μ. UTC+3, ο χρήστης Ryan έγραψε:

While we look into this, can you let me know what version of PDFNet you are using?

Hello there! :slight_smile:

Are there any news on this issue?
If you have not made any progress yet but you are working on it, it is OK.
Or if you don’t want to fix this for some reason, just let us know.

Best Regards,
Kostas

The text on page 4 are part of what is called a Transparency Group. This greatly complicates the conversion process, and results in vector content being converted to an image.

The best way to handle this is to calculate a higher DPI setting. See my post above from June 12.