Pdf alignments looks different in different Orientation mode

Hi team, 

I am using BlinkConverterSettings and HtmltoPdfConverter to convert HTML to Pdf. I am also including Header and Footer while generating pdf.

 When I am using blinkConverterSettings.Orientation = PdfPageOrientation.Portrait, pdf looks fine as per the alignments provided by me for header, footer and content. But If I am setting Orientation as Landscape, the margins for the content got disturbed and it doesn't looks similar as in portrait mode. 

All my alignments using blinkConverterSettings are like this:

BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();

        //Page size - A4 (8.27 * 11.69 inches) using 72 Twips per inch

        blinkConverterSettings.PdfPageSize = new Syncfusion.Drawing.SizeF(595, 842);


        blinkConverterSettings.Margin.Top = 50;

        blinkConverterSettings.Margin.Bottom = 50;

        blinkConverterSettings.Margin.Right = 40;

        blinkConverterSettings.Margin.Left = 40;


        blinkConverterSettings.Scale = 0.6f; //set the content size in pdf


        //Set Blink viewport size

        blinkConverterSettings.ViewPortSize = new Syncfusion.Drawing.Size(523, 770);


Below I have attached  file containing pdf's by setting orientation as portrait and landscape

Please let me know what is the reason of different alignments in both the cases although I have setted the same values for all blinkConverterSettings properties.


Thanks & Regards

Harshit Goel


Attachment: sample2023_a3ed2c7d.zip

4 Replies

SG Sivaram Gunabalan Syncfusion Team May 31, 2023 03:10 PM UTC

We have validated the reported alignment issue with different orientations on our end. The alignment of the content is preserved properly on our end in both portrait and landscape orientations. We have attached code snippet and output documents for your reference,


Code snippet:


HtmlToPdfConverter htmlConverter = new();

 

BlinkConverterSettings settings = new()

{

    PdfPageSize = new SizeF(595, 842),

  Margin = new PdfMargins() { Top = 50, Bottom = 50, Right = 40, Left = 40},

  Orientation = PdfPageOrientation.Landscape,

  Scale = 0.6f

};

 

htmlConverter.ConverterSettings = settings;

string htmlPath = Path.GetFullPath("../../../Data/input.html");

string pdfPath = "LandscapeOutput.pdf";

PdfDocument document = htmlConverter.Convert(htmlPath);

MemoryStream stream = new MemoryStream();

document.Save(stream);

File.WriteAllBytes(pdfPath, stream.ToArray());

document.Close(true);


Kindly share the Input URL, sample or complete code snippet, package details, and environment details with us. It will be for us to reproduce the issue on our end.



HG Harshit Goel replied to Sivaram Gunabalan June 1, 2023 04:56 AM UTC

Thanks for your quick reply, I am generating the pdf on lambda.  I have attached the  complete C# code snippet below of both client and server side below.


Packages I am using for server side are as follows:

Syncfusion.HtmlToPdfConverter.Net.Aws (21.2.6)

Amazon.Lambda.Core (2.1.0)

Amazon.Lambda.Serialization.SystemTextJson (2.3.1)


Packages for client side are as follows:

AWSSDK.Core.3.7.106.40

AWSSDK.Lambda.3.7.110.2

Newtonsoft.Json.13.0.3



Attachment: project_c13489ba.zip


SG Sivaram Gunabalan Syncfusion Team June 1, 2023 10:38 AM UTC

We were able to reproduce the reported alignment issue with orientation in AWS on our end. We will validate the issue and update further details on June 05th,2023.



SG Sivaram Gunabalan Syncfusion Team June 5, 2023 05:19 PM UTC

On our further analysis, we need to set the landscape orientation in the document settings to get the proper landscape and alignment in the output document. In the provided code snippet, we need to set the landscape orientation in the cover page HTML  conversion using BlinkConverterSettings and set the orientation in the cover page document page settings to draw the template in proper alignment and resolve this issue. We have attached the code snippet and output document below for your reference,


Function.cs

//Some code here

    

// Perform HTML to PDF conversion

PdfDocument document = new PdfDocument(input, baseUrl);

 

//Create a new instance of PdfDocument

PdfDocument coverPageDocument = new PdfDocument();

 

//Add cover page HTML

HtmlToPdfConverter coverPageHtmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);

 

blinkConverterSettings = new BlinkConverterSettings();

 

blinkConverterSettings.Orientation = PdfPageOrientation.Landscape;

 

coverPageHtmlConverter.ConverterSettings = blinkConverterSettings;

 

string cbaseUrl = @"";

 

coverPageDocument = coverPageHtmlConverter.Convert("<div id='page1' style='text-align: center;'><p style='padding-top: 500px; font-size: 52px;'>Emergency Operations Plan</p1><p style='font-size: 34px; '>BowMac University</p><p style='font-size: 20px; line-height: 2.0; padding-top: 400px; '><strong> 10 Ontario Street,<br/>Honeoye Falls, New York, NY 14472<br/>585-624-9595<br/><a>www.bowmac.com</a></strong></p><p style='font-size: 18px; padding-top: 50px;>(C) 1999 - 2022 BLUELINE Security Consulting</p></div>", cbaseUrl);

 

for (int i = 0; i < document.Pages.Count; i++)

{

//Get loaded page as template

Syncfusion.Pdf.Graphics.PdfTemplate template = document.Pages[i].CreateTemplate();

               

coverPageDocument.PageSettings.Orientation = PdfPageOrientation.Landscape;

               

//Create new page

PdfPage page = coverPageDocument.Pages.Add();

 

coverPageDocument.Template.Top = CreatePdfHeader(page.GetClientSize().Width);

 

coverPageDocument.Template.Bottom = CreatePdfFooter(page.GetClientSize().Width);

 

//Draw template with the size as loaded page size

page.Graphics.DrawPdfTemplate(template, Syncfusion.Drawing.PointF.Empty, page.GetClientSize());

}


Kindly try the provided solution on your end and let us know the result.


Attachment: sample_94ea88d9.pdf

Loader.
Up arrow icon