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.

Tue Aug 25, 2015 1:36 pm

Hi,

Is there any way to set the page size when converting HTML to PDF

I've used your code from the demo page

PdfDocument doc = new PdfDocument();
doc.PageSettings.Size = PdfPageSize.A3;
String url = "http://www.bbc.co.uk";
Thread thread = new Thread(() =>
{ doc.LoadFromHTML(url, false, true, true); });
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
//Save pdf file.
doc.SaveToFile(Server.MapPath("~") + @"PdfFiles\Output\SimpleHTML.pdf");
doc.Close();
//Launching the Pdf file.
System.Diagnostics.Process.Start(Server.MapPath("~") + @"PdfFiles\Output\SimpleHTML.pdf");

Adding the line doc.PageSettings.Size doesn't seem to do anything as the page is always A4 portrait. Is this the right way or am I missing some code to change the page size. Alternatively how do I get the URL page to fit the output PDF page size.

thanks

Ade
 
Posts: 5
Joined: Thu Aug 20, 2015 11:02 am

Tue Aug 25, 2015 2:02 pm

Bad form replying to my own post but I found out how to do it.

add this

PdfPageSettings page = new PdfPageSettings();
page.Size = PdfPageSize.A3;
page.Orientation = PdfPageOrientation.Landscape;

then

doc.LoadFromHTML(url, false, true, true,page);

but you already know that.
thanks

Ade
 
Posts: 5
Joined: Thu Aug 20, 2015 11:02 am

Wed Aug 26, 2015 8:56 am

Hello,

Thanks for your inquiry.
glad to hear that you solved your issue.
Please feel free to contact us, if you have any questions or needs. We are here for help.

Best Regards,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Return to Spire.PDF