How can I change flattening behaviour when converting from PDF to SVG?

Q:

I’m converting from PDF to SVG with flattening off, and the conversion is inaccurate. If I set the flatten option to fast or simple, the converted page is correct but the pixelization is unacceptably bad. So I can’t use flattening.

A:

One solution may be for you to use Flattener beforehand, flattening from the source PDF to a flattened PDF (which could then be converted to SVG). That would allow you to control the flattening options to get high-quality output (such as SetDPI, SetMaximumImagePixels, or SetThreshold):

http://www.pdftron.com/pdfnet/PDFNet/html/Methods_T_pdftron_PDF_Flattener.htm
http://www.pdftron.com/pdfnet/PDFNet/html/T_pdftron_PDF_Flattener_FlattenMode.htm

For example, you could “pre-flatten” a PDF document with the following code (from http://www.pdftron.com/pdfnet/samplecode.html#Optimizer):

using (PDFDoc doc = new PDFDoc(@“G:\995.pdf”))
{
doc.InitSecurityHandler();

Flattener fl = new Flattener();

// The following lines can increase the resolution of background
// images.
fl.SetDPI(300);
fl.SetMaximumImagePixels(5000000);

// This line can be used to output Flate compressed background
// images rather than DCTDecode compressed images which is the default
fl.SetPreferJPG(false);

// In order to adjust thresholds for when text is Flattened
// the following function can be used.
fl.SetThreshold(Flattener.Threshold.e_keep_most);

// We use e_fast option here since it is usually preferable
// to avoid Flattening simple pages in terms of size and
// rendering speed. If the desire is to simplify the
// document for processing such that it contains only text and
// a background image e_simple should be used instead.
fl.Process(doc,Flattener.FlattenMode.e_fast);

doc.Save(@“G:\995_pre_flattened.pdf”, SDFDoc.SaveOptions.e_linearized);
}

After converting the pre-flattened PDF document to SVG, the output appears quite legible.