I tried so many times to convert Html to Pdf with a landscape orientation but it does not seems to work but same code works with webkit settings.
following is my code:
//Initialize HTML to PDF converter
PdfPageOrientation pdfPageOrientation = !string.IsNullOrEmpty(manifest?.Input?.PageSetup?.Orientation) && manifest.Input.PageSetup.Orientation.ToLower() == "landscape" ? PdfPageOrientation.Landscape : PdfPageOrientation.Portrait;
SizeF pdfpageSize = GetSyncfusionPdfPageSize(manifest.Input?.PageSetup?.Size.ToUpper(), pdfPageOrientation);
htmlDocument = ReplacePageBreakTags(htmlDocument);
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);
BlinkConverterSettings blinkSettings = new BlinkConverterSettings();
//add the header in outside bounds of margin
if (!string.IsNullOrEmpty(header))
{
blinkSettings.PdfHeader = HeaderHTMLtoPDFSyncfusionBlink(header, margin.HeaderMargin, pdfPageOrientation, pdfpageSize, manifest);
}
else
{
blinkSettings.PdfHeader = HeaderTexttoPDFSyncfusionBlink(headerText, margin.HeaderMargin, pdfPageOrientation, pdfpageSize, manifest);
}
if (!string.IsNullOrEmpty(footer))
{
blinkSettings.PdfFooter = FooterHTMLtoPDFSyncfusionBlink(footer, margin.FooterMargin, manifest.Input.IncludePageNumber, pdfPageOrientation, pdfpageSize, manifest);
}
else
{
blinkSettings.PdfFooter = FooterTexttoPDFSyncfusionBlink(footerText, margin.FooterMargin, manifest.Input.IncludePageNumber, pdfPageOrientation, pdfpageSize, manifest);
}
blinkSettings.ViewPortSize = new Syncfusion.Drawing.Size(1024, 800);
blinkSettings.Orientation = pdfPageOrientation;
blinkSettings.PdfPageSize = pdfpageSize;
blinkSettings.EnableJavaScript = true;
blinkSettings.Margin.Top = 0;
blinkSettings.Margin.Bottom = 0;
blinkSettings.Margin.Left = 0;
blinkSettings.Margin.Right = 0;
htmlConverter.ConverterSettings = blinkSettings;
//Convert html string to PDF
using (Syncfusion.Pdf.PdfDocument document = htmlConverter.Convert(htmlDocument, ""))
{
using (var stream = new MemoryStream())
{
//Save and close the PDF document
document.Save(stream);
document.Close(true);
if (manifest.AddCoverPage)
{
PdfDocument documentWithCoverPage = new PdfDocument();
PdfSection section1 = documentWithCoverPage.Sections.Add();
section1.PageSettings.Margins.All = 0;
PdfPage coverpage = section1.Pages.Add();
PdfGraphics graphics = coverpage.Graphics;
RectangleF bounds = new RectangleF(PointF.Empty, coverpage.GetClientSize());
PdfBitmap image = new PdfBitmap(images[0]);
graphics.DrawImage(image, 0, 0);
PdfBitmap subImage = new PdfBitmap(images[1]);
graphics.DrawImage(subImage, 70, 650);
PdfSection section2 = documentWithCoverPage.Sections.Add();
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);
documentWithCoverPage.Append(loadedDocument);
using (var streamdocumentWithCoverPage = new MemoryStream())
{
documentWithCoverPage.Save(streamdocumentWithCoverPage);
documentWithCoverPage.Close(true);
return streamdocumentWithCoverPage.ToArray();
}
}
else
{
return stream.ToArray();
}
}
Hi Duminda,
We are unable to reproduce the reported issue with our testing documents. We suspect the reported issue may occur for particular documents. However, we have attached the sample with the provided code snippet for your reference.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Lanscape_HTMLtoPDF-1557983195
Kindly try the sample and let us know the result. If you are still facing the issue, we kindly request you to share the modified sample, input HTML/URL with resources, package name, and package version with us to replicate the same issue on our end. This will be more helpful for us to analyze and provide you with a prompt solution.
Regards,
Karmegam
Hi,
I worked with above code, orientation is now ok but I find a white border on right and bottom side of the generated document, I have attached code and resulting document for reference.
Thank you.
We can see the white border on the right and bottom of the page in the provided document. However, we are unable to reproduce the reported issue with our testing documents. We have attached the modified sample with the cover page code snippet for your reference.
Kindly try the sample with your input documents and let us know the result. If you are still facing an issue, we kindly request you to share the modified sample, input HTML/URL with resources, package name, package version, and environment details with us to replicate the same issue on our end. This will be more helpful for us to analyze and provide you with a prompt solution.
Hi,
Tried to generate the document with the provided sample project still shows the white border in the generated document. Resulting document is attached herewith.
Thank you.
Attachment: HTMLtoPDF_a81f5967.zip
We are unable to reproduce the reported issue with our testing documents. We suspect that the issue is document-specific. Therefore, we request you share the input URL/ HTML with us so that we can replicate the problem on our end. It will be more helpful for us to analyze further and provide you with a prompt solution