Html to PDF - Rendering options?

We have an html rendering method we want to replace with Aspose. Currently we have embedded CSS in the markup we want to convert. Our current rendering seems to assume 96dpi and all of the content is about 25% larger (72 dpi) than the original. We’re using the html media type of “print” in our styles for pdf rendering.

So instead of rewriting all of our styles is there any way to change the resolution of the rendered pdf? Perhaps there’s a way using Facades to capture “rendered” content and save that to a pdf?

Thanks for any assistance!

@williamfa

Thank you for contacting support.

You may Convert HTML to PDF with Aspose.PDF for .NET API and generated PDF file will exactly look like the HTML file, as it is manually printed by a browser. So you do not need to change resolution or other properties because generated file will not have differences.

In case you notice any difference then please share source and generated files along with narrowed down code snippet so that we may try to reproduce and investigate it in our environment.

Hi @Farhan.Raza ,

I’m waiting for the OEM Site license payment to be approved but hopefully you can help here in the mean time.

I’ve created a zip archive with the raw markup and the Original96.pdf showing the previous method with the New72.pdf showing the Aspose output from the same markup. Snippet.txt has the relevant code.

The dpi value is just to get the page size consistent with the original pdf documents.

Here’s a link to the information comparison.zip (https://drive.google.com/file/d/1sVNUyHhZK4Stm7w-KC63kBwyRdGBHt5g/view?usp=sharing)

byte[] pdfBytes = new byte[] {};
double dpi = 72.00;
var bean = new MarkupResponse();
try
{
	HtmlLoadOptions options = new HtmlLoadOptions();
	options.PageInfo = new PageInfo();
	options.PageInfo.Width = dpi * 8.26;
	options.PageInfo.IsLandscape = false;
	options.PageInfo.Margin = new MarginInfo();
	options.PageInfo.Margin.Left = 0.00;
	options.PageInfo.Margin.Right = 0.00;
	options.HtmlMediaType = HtmlMediaType.Print;

	// Convert string to bytes and convert to pdf document
	byte[] byteArray = Convert.FromBase64String(request.Content);
	Aspose.Pdf.Document pdfDocument;
	using (var fs = new MemoryStream(byteArray))
	{
		pdfDocument = new Aspose.Pdf.Document(fs, options);
		pdfDocument.EmbedStandardFonts = true;
	}

	// Convert pdf document object into byte array
	using (var pdfStream = new MemoryStream())
	{
		pdfDocument.Save(pdfStream, SaveFormat.Pdf);
		pdfBytes = pdfStream.ToArray();
	}
}
catch (Exception ex)
{
	bean.Error = "DocumentLogic.ProcessMarkup " + ex.Message;
}

@williamfa

Thank you for the details.

Would you please elaborate your requirements a little more, while comparing shared PDF documents and mentioning what specifically do you expect or look forward to, in Aspose.PDF for .NET API to satisfy your requirements. We will address your concerns accordingly.

When documents are electronically signed on our web portal we upload the markup and convert it to a pdf for storage. Some documents are government forms with specific layouts and some are just for a permanent record in our document storage system.

Our existing conversion is a cumbersome and unreliable process involving a unix server and a shell process with temporary files. The examples I sent show the original which seems to be 96dpi while the new output with Aspose is 72dpi so the current styles do not look right. So instead of changing all of our templates I’d like to know if there’s a way to change the rendering to be 96 dpi in the new pdf document created from the markup.

If you look at the old and new examples the new version with Aspose has a number of typical issues due to the content being 25% larger. Do we need to redo all of our templates or does Aspose have options to change the rendering to be 96dpi?

@Farhan.Raza btw, I put in a temporary license now so the watermark is gone and the full number of pages are rendered but the original dpi resolution issue still exists. Thanks!

@williamfa

Thank you for elaborating it.

We have logged an investigation ticket with ID PDFNET-45743 in our issue management system for detailed analysis of your requirements. We will let you know as soon as some significant updates will be available in this regard.

@Farhan.Raza This may be a duplicate or at least related to PDFNET-41078. Was anything ever resolved there?

@williamfa

We are afraid PDFNET-41078 has not been resolved owing to some important and critical issues. We have raised its priority to next level and we will take care of your concerns accordingly. We appreciate your patience and comprehension in this regard.

Is there any likelihood that setting the resolution of the generated pdf will ever be implemented? Not having this ability has limited the implementation of the Aspose PDF for .NET we licensed due to existing content being 96 dpi rather than the supported 72 dpi.

@williamfa

Thank you for getting back to us.

We are afraid PDFNET-45743 has not been scheduled yet. We have recorded your concerns and will let you know as soon as any significant update will be available. We are thankful to you for your patience.