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

Free Support Forum - aspose.com

Error: 49.4C02. Unable to print pdf. Creted by converting HTML to PDF

Hi


I am unable to print the pdf that I have created using aspose.pdf. I have converted HTML string to pdf.

Printer: HP M4345 MFP
Driver: HP Universal Printing PS (v5.9.0).

Below is the code:

var pdfLicense = new Aspose.Pdf.License();
pdfLicense.SetLicense(HttpContext.Current.Server.MapPath("~") + “\Aspose.Total.lic”);

string path = HttpContext.Current.Server.MapPath("~");
try
{
var pdfHTML = new StringBuilder();
pdfHTML.AppendFormat("" +
//"<link rel=“stylesheet” type=“text/css” href="{0}\Content\print.css">" +
//"<link rel=“stylesheet” type=“text/css” href="{0}\Content\bootstrap.min.css">" +
“<body class=“print-body”>”
, path);
pdfHTML.Append(
“<div class=“row print-header”>” +
“<div class=“pull-left”>” +
“<div class=“inline big-font”>” +
"  TEST PDF" +
” +
” +
“<div class=“pull-right”>” +
“<div class=“profileWrapper”>” +
” +
“Employy Name” +
“” +
” +
“<div class=“right-padding-15”>” +
” +
“Today’s Date” +
“” +
” +
” +
”);


pdfHTML.Append("

");

pdfHTML.AppendFormat(
“<div class=“col-xs-20 mainContent”>” +
“<div class=“row”>” +
“<div class=“pull-left printPage-submitOffice”>” +
” +
“Submitted to {0}” +
“” +
” +
” +
“<div class=“row”>” +
“<div class=“col-sm-14”>” +
“<div id=“viewByWrapper”> " +
“<div id=“viewBy”>” +
Items Found: {1}” +
"   " +
Total {2} Amount: {3} {2}” +
” +
” +
” +
, “City Name”
, “1”
, “Currency”
, “500.00”);

pdfHTML.Append(”<div class=“row”>");

pdfHTML.Append("<table class=“print-table”> #<th style=“width: 100px”>DATECODE<th style=“width: 230px”>TYPECURRENCY FOREIGN AMOUNT EXCHANGE RATE LOCAL AMOUNT<th style=“width: 90px”>TAX");
pdfHTML.Append("");
pdfHTML.AppendFormat(
“” +
“{0}” +
“{1}” +
“{2}” +
“{3}” +
“{4}” +
“{5}” +
“{6}” +
“{7}” +
“{8}” +
, “1”
, “23-Mar-2017”
, “XYZ”
, “XYZ”
, “INR”
, “”
, “”
, “500.00”
, “19.00%”);

pdfHTML.Append("
");

pdfHTML.Append("");
var htmlLoadOptions = new HtmlLoadOptions();
htmlLoadOptions.PageInfo.Margin.Top = 270;
htmlLoadOptions.PageInfo.Margin.Left = 30;
htmlLoadOptions.PageInfo.IsLandscape = true;
var pdf = new Document(new MemoryStream(Encoding.UTF8.GetBytes(pdfHTML.ToString())), htmlLoadOptions);
for (int i = 1; i <= pdf.Pages.Count; i++)
pdf.Pages[i].SetPageSize(792, 612);
pdf.PageMode = PageMode.UseThumbs;
JavascriptAction javascript = new JavascriptAction(“this.print({bUI:true,bSilent:false,bShrinkToFit:true});”);
pdf.OpenAction = javascript;
pdf.Save(path + “\ThisPDFNotPrinting.pdf”);


I am using 17.1.0 version of Aspose.
I am able to print other pdf files. Only the pdf files generated using Aspose are not printing.

Hi There,


Thanks for contacting support.

I have tested the scenario with your code using Aspose.Pdf for .NET 17.1.0 and I was able to save ThisPDFNotPrinting.pdf. When I open up the PDF file, it popup the print dialogue for printing. I have attached the PDF file for your reference, if you open the PDF file, it will popup Print Dialogue Box. If you want to print from code then PDFViewer class of Aspose.Pdf API allows you to print PDF file to the printer. Please go through our documentation Working with Printing (Facades) for details with example.

If you still face any issues, please feel free to contact us.

We are sorry for the inconvenience.

Best Regards,

Hi

If you try to print that file on a HP Universal Printing Driver (v5.9.0). It fails, the printer gives error 49.4C02

It is happening only for pdf generated using aspose.pdf

Hi There,


Thanks for sharing further details.

I have tested the scenario with your code and am able to save the “ThisPDFNotPrinting.pdf” file successfully. Also I did not notice any issue when trying to print the file generated file with latest release of Aspose.Pdf for .NEt 17.3.0. I have attached the generated PDF file for your reference.

We are sorry for the inconvenience.

Best Regards