Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Aug 12, 2022 7:54 am

Hi,

I am using the following function to create PDF.

HtmlConverter.Convert(@"D:\Exelon-Proj-data\HTML_Samples\M212.html", fileName,

//enable javascript
true,

//load timeout
100 * 1000,

//page size
new Size(612, 792),
//new Size(700, 500),


//page margins
new PdfMargins(10, 60));

I am just confused about how can I give page orientation (Landscape, portrait) by using this "new Size (612, 792)" parameter, because I don't know the exact Hight and width for Portrait and Landscape. please help me in this.

haidersoft10P
 
Posts: 6
Joined: Wed Aug 03, 2022 12:05 pm

Fri Aug 12, 2022 9:19 am

Hello,

Thanks for your inquiry.

When the width of size is greater than the height, the resulting PDF page is Landscape and the opposite is Portrait. Therefore, you don't have to care about their specific values. You can set any size.
Also, these dimensions are in Points rather than Pixels. You can resize PDF pages according to the dimensions of the HTML. Hope it helps you.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Mon Aug 22, 2022 7:47 am

Thanks for your response yes you are saying right we don't need to care about a specific page size we can set any but i need a spefic hight and width ( according to standerds), as well there are 2 size functions (overload forms) available in Spire.PDF mentioned below.

1-public Size(Point pt)
2-public Size(int width, int height)

I am using 2nd one. please give me numbers( width, hight) for landScap and portrate that you think that are suitable.

And other this Page size, can you please tell me how can i set page size (a4). I have already shared my code in 1st post. we are in final stage of POC of SpirePDF if we would find any appropriate answers on this then we'll contact with your sales team.

Thanks
Haider Ali
Senior Software Engineer

haidersoft10P
 
Posts: 6
Joined: Wed Aug 03, 2022 12:05 pm

Mon Aug 22, 2022 10:24 am

Hi Haider ,

Thanks for your reply.

For A4 page size, you can use PdfPageSize.A4 to set it. And for landscape mode, just exchange the height and width. Here is the sample code. I'm not sure if I understand your needs correctly. If I misunderstood, please point out some examples to help me get it.

Code: Select all
            HtmlConverter.Convert(@"D:\Exelon-Proj-data\HTML_Samples\M212.html", fileName,
                //enable javascript
                true,
                //load timeout
                100 * 1000,

                //a4
                //PdfPageSize.A4,
                //a4 landscape
                new SizeF(PdfPageSize.A4.Height, PdfPageSize.A4.Width),
 
                //page margins
                new PdfMargins(10, 60));
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Mon Aug 22, 2022 1:04 pm

Hi,

How can i share file with you? may i could give you better understanding this way, i am successfully able to create pdf with spire.pdf, performance, content creation everything is good just only is issue is page size. i need an exact number for (landscape, portrait) against A4 page size.

or if we could connect on call shortly that is way better than anything.

Thanks
Haider Ali

haidersoft10P
 
Posts: 6
Joined: Wed Aug 03, 2022 12:05 pm

Tue Aug 23, 2022 6:15 am

I Think i couldn't give you a better understanding :roll: . let me give you an emaple .

if (sectionsDetails[item.index].IsSectionLandscape)
{
//Landscape
this.Width = 1122;
this.Height = 793;

}
else {
//Portrait
this.Height = 1122;
this.Width = 793;

}

These are the height and width that I am using for now but it gave me too wider page, may It will not fit on a4 when I’ll print, one way is hit and trail method, I’ll pick random height and width and do it recursively until I’ll get a perfect one or you give me a Hight and width that will be perfect fit on a4 page.

haidersoft10P
 
Posts: 6
Joined: Wed Aug 03, 2022 12:05 pm

Tue Aug 23, 2022 10:02 am

Hi Haider,

Thanks for your reply.

For the page size "A4", its width is 595(pt) and height is 842(pt). So you can use "new SizeF(595,842)" to set the page size to A4 or just use the static variable "PdfPageSize.A4" in Spire.Pdf to set the page size to "A4". Here is the code.
If you need to share files with us, please send them to support@e-iceblue.com via email. Thanks in advance.

Code: Select all
            if (sectionsDetails[item.index].IsSectionLandscape)
            {
                //Landscape
                this.Width = PdfPageSize.A4.Height;  //842
                this.Height = PdfPageSize.A4.Width;  //595

            }
            else
            {
                //Portrait
                this.Height = PdfPageSize.A4.Width; //595
                this.Width = PdfPageSize.A4.Height; //842

            }
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Tue Aug 23, 2022 10:25 am

Thanks for your help. I just try this and the result looks fine to me.

haidersoft10P
 
Posts: 6
Joined: Wed Aug 03, 2022 12:05 pm

Tue Sep 20, 2022 6:33 am

Hello,

Thanks for your feedback.
Please feel free to contact us if you have any issues.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF