I have tried to render my html into a PDF but it doesn’t fit to a A4 and for that it is truncated at the right. I have tried the same html with other renderer an all does a scale to fit it to A4 by default. How can I do this in Aspose. You can see my solution as attachment.
Thankstest.zip (195.8 KB)
test.zip (195.8 KB)
I have shared sample code with . This will help you to achieve your requirements. Please share feedback with us if there is still an issue.
string Resultant_output = path + "output.pdf";
// Create PdfRendering Options object
Aspose.Html.Rendering.Pdf.PdfRenderingOptions pdf_options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions();
pdf_options.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(
new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Unit.FromInches(8.27),
Aspose.Html.Drawing.Unit.FromInches(11.69)),
new Aspose.Html.Drawing.Margin(0));
// Instantiate PdfDevice object while passing PdfRenderingOptions and resultant file path as arguments
using (Aspose.Html.Rendering.Pdf.PdfDevice pdf_device = new Aspose.Html.Rendering.Pdf.PdfDevice(pdf_options, Resultant_output))
// Create HtmlRenderer object
using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
// Create HtmlDocument instance while passing path of already created HTML file
using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(path+"source.html"))
{
// Render the output using HtmlRenderer
renderer.Render(pdf_device, html_document);
}
Hi @Adnan.Ahmad sorry for the late feedback. One question I have to work with html strings and output streams and not with local files. Can I do this also with PDFDevice anch html renderer?
Thanks Christoph
Hi @Adnan.Ahmad ok no i works with in memory but result is the same like in my code. the problem is the AtPagePriority = AtPagePriority.CssPriority
But if I look at the html and try to print this is always a A4 and not shrinked
Can you please explain issue in more details along with screenshots and samples so that i may understand better to help.