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.

Thu Oct 16, 2014 5:45 pm

After creating the pdf, when I go to print it always prints portrait. The code is below, any help would be great.

PdfHtmlLayoutFormat pdfHtml = new PdfHtmlLayoutFormat();
PdfDocument doc = new PdfDocument();
PdfPageSettings ps = new PdfPageSettings();

pdfHtml.FitToHtml = Clip.None;
pdfHtml.Layout = PdfLayoutType.Paginate;

var letter = PdfPageSize.A4;

ps.Orientation = PdfPageOrientation.Landscape;
ps.Margins.Top = 10;
ps.Margins.Bottom = 10;
ps.Size = letter;

String url = "internal url";

doc.LoadFromHTML(xxx, false, false, true, ps, pdfHtml);

doc.PrintDocument.PrinterSettings.DefaultPageSettings.Landscape = true;
doc.PrintDocument.PrinterSettings.DefaultPageSettings.Margins.Left = (int) .25;
doc.PrintDocument.PrinterSettings.DefaultPageSettings.Margins.Right = (int) .25;
doc.PageScaling = PdfPrintPageScaling.FitSize;
doc.PrintDocument.Print();

doc.SaveToFile(@"c:\zzz.pdf");
doc.Close();

PDFDocumentViewer(@"c:\zzz.pdf");

bdw1969
 
Posts: 6
Joined: Fri Sep 12, 2014 5:28 pm

Fri Oct 17, 2014 2:52 am

Dear bdw1969,

Thanks for your inquiry.

I have used the code snippet you provided to test, the result document(SaveToFile method) and the print document(Print() method) are both landscape. Please check out the code snippet or printer settings.

Plus:I used spire.pdf_hotfix_3.1.53.

Best regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Fri Oct 17, 2014 8:48 am

Once I used spire.pdf_hotfix_3.1.53, the landscape worked, Thanks.

One other issue is that the left and right sides of the data are cut off? Is there a way to make it all fit? Shrink the font size of something?

bdw1969
 
Posts: 6
Joined: Fri Sep 12, 2014 5:28 pm

Fri Oct 17, 2014 9:33 am

Dear bdw1969,

For your requirement, you can set these two properties with following value:
Code: Select all
format.FitToHtml = Clip.None; //None, Width, Height, Both
format.FitToPage = Clip.None; //None, Widht, Height, Both

Best regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Fri Oct 17, 2014 10:11 am

Thanks for the reply, here is my updated code, and the pdf. Note that the left and right sides are still cut off?

Any more suggestions?

String xxx= "//internal";
PdfHtmlLayoutFormat pdfHtml = new PdfHtmlLayoutFormat();
PdfDocument doc = new PdfDocument();
PdfPageSettings ps = new PdfPageSettings();

pdfHtml.FitToHtml = Clip.None;
pdfHtml.FitToPage = Clip.None;

var letter = PdfPageSize.A4;

ps.Orientation = PdfPageOrientation.Landscape;
ps.Margins.Top = 10;
ps.Margins.Bottom = 10;
ps.Size = letter;

doc.LoadFromHTML(xxx, false, false, true, ps, pdfHtml);

doc.PrintDocument.PrinterSettings.DefaultPageSettings.Landscape = true;
doc.PrintDocument.PrinterSettings.DefaultPageSettings.Margins.Left = (int).25;
doc.PrintDocument.PrinterSettings.DefaultPageSettings.Margins.Right = (int).25;
doc.PageScaling = PdfPrintPageScaling.FitSize;
doc.PrintDocument.Print();

doc.SaveToFile(@"c:\xxx.pdf");
doc.Close();

bdw1969
 
Posts: 6
Joined: Fri Sep 12, 2014 5:28 pm

Mon Oct 20, 2014 1:51 am

Dear bdw1969,

Please provide the html file or the url you tried to convert to help us reproduce the issue.

Best Regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Mon Oct 20, 2014 12:34 pm


bdw1969
 
Posts: 6
Joined: Fri Sep 12, 2014 5:28 pm

Tue Oct 21, 2014 1:25 am

Dear bdw1969,

The url you provided is not available.
Please make sure that the url is valid or you can send us the html file.

Best Regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Tue Oct 21, 2014 11:15 am

Here is the html file.

bdw1969
 
Posts: 6
Joined: Fri Sep 12, 2014 5:28 pm

Wed Oct 22, 2014 2:26 am

Dear bdw1969,

Thanks for your reply.

Please refer to the code below:
Code: Select all
PdfDocument pdf = new PdfDocument();

PdfHtmlLayoutFormat format = new PdfHtmlLayoutFormat();
format.FitToPage = Clip.Both;
format.Layout = PdfLayoutType.Paginate;

PdfPageSettings settings = new PdfPageSettings();
var letter = PdfPageSize.A3; //Chage it with A3, A4 is small
settings.Orientation = PdfPageOrientation.Landscape;
settings.Margins.Top = 10;
settings.Margins.Bottom = 10;
settings.Size = letter;
pdf.LoadFromHTML(@"xxxx", true, true, false, settings, format);
pdf.PrintDocument.PrinterSettings.DefaultPageSettings.Margins.Left = (int).25;
pdf.PrintDocument.PrinterSettings.DefaultPageSettings.Margins.Right = (int).25;
pdf.PageScaling = PdfPrintPageScaling.FitSize;
pdf.PrintDocument.Print();
pdf.SaveToFile("report.pdf");


Best Regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Fri Oct 24, 2014 7:50 am

Dear bdw1969,

Has your problem been resolved?
If not, please send more information to help us resolve it.

Best Regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Mon Oct 27, 2014 11:26 am

Yes it is resolved thanks for your assistance.

bdw1969
 
Posts: 6
Joined: Fri Sep 12, 2014 5:28 pm

Tue Oct 28, 2014 1:02 am

Dear bdw1969,

Please feel free to contact us if you have any problem.

Best Regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Fri Jan 27, 2017 7:25 pm

I tried most of the code above to print but no matter what I try, the right side of the HTML page that I try to convert gets cut-off in the PDF document creted. Here is the code I used below:

PdfDocument doc = new PdfDocument();

PdfHtmlLayoutFormat format = new PdfHtmlLayoutFormat();
format.FitToPage = Clip.Both;
format.Layout = PdfLayoutType.Paginate;

PdfPageSettings settings = new PdfPageSettings();
var letter = PdfPageSize.A3; //Chage it with A3, A4 is small
settings.Orientation = PdfPageOrientation.Landscape;
settings.Margins.Top = 10;
settings.Margins.Bottom = 10;
settings.Size = letter;

String url = Request.Url.AbsoluteUri;
Thread thread = new Thread(() =>

{ doc.LoadFromHTML(url, false, true, true); });

thread.SetApartmentState(ApartmentState.STA);

thread.Start();

thread.Join();

doc.PrintDocument.PrinterSettings.DefaultPageSettings.Margins.Left = (int).25;
doc.PrintDocument.PrinterSettings.DefaultPageSettings.Margins.Right = (int).25;
doc.PageScaling = PdfPrintPageScaling.FitSize;

//Save pdf file.

doc.SaveToFile("PO_Report_Saved.pdf");

doc.Close();

//Launching the Pdf file.

System.Diagnostics.Process.Start("PO_Report_Saved.pdf");

Please let me know what I am missing

jmoore00
 
Posts: 1
Joined: Wed Jan 18, 2017 7:08 pm

Mon Jan 30, 2017 3:37 am

Dear jmoore00,

Sorry for late reply as weekend.
Please change this code
Code: Select all
 doc.LoadFromHTML(url, false, true, true);

to the code
Code: Select all
doc.LoadFromHTML(url, false, true, true,settings);

If there is any question, please let me know.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF