We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to print PDF as is (text) not image?

HiI use this code to print a pdf file to a virtual printer.

private void printPdfDocument(string pdfDocument)
{
//create PdfViewer object
PdfViewer viewer = new PdfViewer();

//open input PDF file
viewer.OpenPdfFile(pdfDocument);

//set attributes for printing
viewer.AutoResize = true; //print the file with adjusted size
viewer.AutoRotate = true; //print the file with adjusted rotation
viewer.PrintPageDialog = false; //do not produce the page number dialog when printing

//create objects for printer and page settings and PrintDocument
System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();
System.Drawing.Printing.PrintDocument prtdoc = new System.Drawing.Printing.PrintDocument();

//set printer name
//ps.PrinterName = prtdoc.PrinterSettings.PrinterName;

ps.PrinterName = "PDF-XChange Conversion System";
//set PageSize (if required)
pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);

//set PageMargins (if required)
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);

//print document using printer and page settings
viewer.PrintDocumentWithSettings(pgs, ps);

//close the PDF file after priting
viewer.ClosePdfFile();
} private void printPdfDocument(string pdfDocument)
{
//create PdfViewer object
PdfViewer viewer = new PdfViewer();

//open input PDF file
viewer.OpenPdfFile(pdfDocument);

//set attributes for printing
viewer.AutoResize = true; //print the file with adjusted size
viewer.AutoRotate = true; //print the file with adjusted rotation
viewer.PrintPageDialog = false; //do not produce the page number dialog when printing

//create objects for printer and page settings and PrintDocument
System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings();
System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();
System.Drawing.Printing.PrintDocument prtdoc = new System.Drawing.Printing.PrintDocument();

//set printer name
//ps.PrinterName = prtdoc.PrinterSettings.PrinterName;

ps.PrinterName = "PDF-XChange Conversion System";
//set PageSize (if required)
pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);

//set PageMargins (if required)
pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);

//print document using printer and page settings
viewer.PrintDocumentWithSettings(pgs, ps);

//close the PDF file after priting
viewer.ClosePdfFile();
}

But when I do the output is printed as an image. My virtual printer scans for text so since it's an image it can't do this. For instance If I use Acrobat reader to print a pdf to this printer it works fine, but If i use Aspose.PDF to print it can't scan the text since it's printed as an image.Is there way to change the settings in the API, so when you print it it's printed with characters not glyphs.

See the example i've attached, the "original Letter.pdf" you can select text in acrobat reader, but "Aspose Printed Letter.pdf" is printed as an image, and you can't select any text.

Please let me know if there's a way to fix this in code?

Hi Arjuna,


Thanks
for using our products.

I am afraid currently Aspose.Pdf for .NET prints text inside PDF file as vector graphics. However for the
sake of correction (print/render text as text), I have logged it in our issue tracking system as
PDFNEWNET-34279. We will investigate this
issue in details and will keep you updated on the status of a correction.

We apologize for your inconvenience.

PS, please note that we are already aware of this limitation and in order to support the new feature, we might require some month because its a major improvement (may be this feature will become early next year).

Hi Arjuna,


Thanks for your patience.

I am pleased to share that the issue reported earlier has been resolved. Please try using following code lines when printing the PDF files so that the text in output file appears as text rather than vector graphics.
The hotfix will become available in upcoming release version of Aspose.Pdf for .NET 7.7.0.

[C#]

FontRepository.Substitutions.Add(new SystemFontsSubstitution(SubstitutionFontCategories.TheSameNamedEmbeddedFonts));<o:p></o:p>

var viewer = new PdfViewer();

viewer.RenderingOptions.SystemFontsNativeRendering = true;

The issues you have found earlier (filed as PDFNEWNET-34279) have been fixed in Aspose.Pdf for .NET 7.7.0.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hello Nayyer,

does the code snippet mean that this only works with fonts available on the system and not with fonts embedded in the PDF? Do you plan to extend this to embedded fonts?

Is there any dependency on the type of printer driver? Does this work for PostScript printer drivers as well?

BR

Hi there,


Sorry for the inconvenience faced. We are looking into your issue and will update you soon.

Best Regards,

Hi,

do you have an update on this question? I am still waiting for it.

BR

Hi there,


Sorry for the inconvenience faced. You are right system installed fonts can be embedded to output document. Moreover, there is no dependency on the printer driver and it also works for PostScript printers.

Please feel free to contact us for any further assistance.

Best Regards,

Hi,


coming back to this issue. Did you make any improvements to also support embedded fonts from the PDF file to be used by (downloaded to) the printer driver? The postscript printer could then embed these fonts, instead of using vector graphics for all the text glyphs.

Thanks

Hi there,


Thanks for your inquiry. Please note, as suggested above, Aspose.Pdf can use embedded fonts of PDF file if these are installed on the system. You may substitute non available fonts with system default font or some custom font as following. These settings print text as characters instead vector graphics. However if you have some different requirement then please share some more details, so we will guide you accordingly.

  • Embedded fonts that don’t have equivalent between system fonts can be substituted with system default font (Times New Roman) with following setting

// Substitute all embedded fonts (fonts
that have no equivalent between system fonts are substituted with Times New
Roman)
<o:p></o:p>

FontRepository.Substitutions.Add(new SystemFontsSubstitution(SubstitutionFontCategories.AllEmbeddedFonts));

//create PdfViewer object and bind PDF file

PdfViewer pdfViewer = new PdfViewer();

pdfViewer.RenderingOptions.SystemFontsNativeRendering = true;


  • Default font can be defined to substitute any embedded font that has no equivalent between system fonts

SystemFontsSubstitution systemFontsSubstitution = new SystemFontsSubstitution(SubstitutionFontCategories.AllEmbeddedFonts);

systemFontsSubstitution.DefaultFont = FontRepository.FindFont("MSGothic");

FontRepository.Substitutions.Add(systemFontsSubstitution);

//create PdfViewer object and bind PDF file

PdfViewer pdfViewer = new PdfViewer();

pdfViewer.RenderingOptions.SystemFontsNativeRendering
= true;


Best Regards,