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 Aug 18, 2016 7:17 am

I am saving a website link to PDF document but what happening is , it's not saving the full width of page size, I have edited page size property before saving but still edges are cutting from right side.

below is my code in c#:
Code: Select all
PdfDocument doc = new PdfDocument();
                PdfPageSettings settings = new PdfPageSettings();   

                Spire.Pdf.PdfPageSettings pdfse = new PdfPageSettings();
                pdfse.Orientation = PdfPageOrientation.Landscape;
                SizeF sizeff = new SizeF(browse.Document.Body.OffsetWidth, 1100);
                pdfse.Size = sizeff;
                doc.PageSettings = pdfse;               
                //pset.PaperSize = pdfse;
                //doc.PageSettings = pset;
                doc.LoadFromHTML(browse.Url.AbsoluteUri,false, true, false, settings);
                doc.PrintDocument.DefaultPageSettings.Landscape = true;
                PaperSize psizee = new PaperSize();
                psizee.Height = (int)sizeff.Height;
                psizee.Width = (int)sizeff.Width;
                doc.PrintDocument.DefaultPageSettings.PaperSize = psizee;
                //psize = doc.PrintDocument.DefaultPageSettings.PaperSize;               
                //psize.Width = bp.Width;
                //doc.PrintDocument.DefaultPageSettings.PaperSize = psize;
                doc.SaveToFile("FromHTML.pdf");
                doc.Close();

I just want to grab all the page visible area so i may print it.
Last edited by Ghouri0007 on Thu Aug 18, 2016 10:03 am, edited 1 time in total.

Ghouri0007
 
Posts: 6
Joined: Wed Aug 17, 2016 12:48 pm

Thu Aug 18, 2016 8:13 am

Dear Ghouri0007,

Thanks for your inquiry.
I found you used settings in the method LoadFromHTML(), but didn't set the value for settings, only set the value for pdfse, please set the setting value or change settings to pdfse. And then please add following code before setting the PaperSize.
Code: Select all
                    psizee.RawKind = (int)PaperKind.Custom;
                    doc.PrintDocument.DefaultPageSettings.PaperSize = psizee;

If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Aug 18, 2016 9:25 am

I did this and its not working yet, still cutting from left.

Code: Select all
        private void cmdprint_Click(object sender, EventArgs e)
        {
            try
            {             
                PdfDocument doc = new PdfDocument();
                PdfPageSettings settings = new PdfPageSettings();   

                Spire.Pdf.PdfPageSettings pdfse = new PdfPageSettings();
                pdfse.Orientation = PdfPageOrientation.Landscape;
                SizeF sizeff = new SizeF(browse.Document.Body.OffsetWidth, 1100);
                pdfse.Size = sizeff;
                doc.PageSettings = pdfse;               
                //pset.PaperSize = pdfse;
                //doc.PageSettings = pset;
                doc.LoadFromHTML(browse.Url.AbsoluteUri,false, true, false, settings);
                doc.PrintDocument.DefaultPageSettings.Landscape = true;
                PaperSize psizee = new PaperSize();
                psizee.Height = (int)sizeff.Height;
                psizee.Width = (int)sizeff.Width;
                psizee.RawKind = (int)PaperKind.Custom;
                doc.PrintDocument.DefaultPageSettings.PaperSize = psizee;
                //doc.PrintDocument.DefaultPageSettings.PaperSize = psizee;
                //psize = doc.PrintDocument.DefaultPageSettings.PaperSize;               
                //psize.Width = bp.Width;
                //doc.PrintDocument.DefaultPageSettings.PaperSize = psize;
                doc.SaveToFile(System.DateTime.Now.Millisecond.ToString() + ".pdf");
                doc.Close();
                PDFDocumentViewer("FromHTML.pdf");

            }
            catch (Exception ex)
            {
            }
        }

Ghouri0007
 
Posts: 6
Joined: Wed Aug 17, 2016 12:48 pm

Thu Aug 18, 2016 9:39 am

Dear Ghouri0007,

Thanks for your reply.
From the codes you just provided, still didn't set the value of settings, here is sample code for your reference:
Code: Select all
                    PdfDocument doc = new PdfDocument();
                    PdfPageSettings settings = new PdfPageSettings();
                    settings.Size = new SizeF(2000, 1100);
                    doc.LoadFromHTML("http://www.e-iceblue.com/forum/", false, true, false, settings);                                       
                    PaperSize psizee = new PaperSize();
                    psizee.Height = (int)settings.Size.Height;
                    psizee.Width = (int)settings.Size.Width;
                    psizee.RawKind = (int)PaperKind.Custom;
                    doc.PrintDocument.DefaultPageSettings.PaperSize = psizee;
                    doc.PrintDocument.Print();
                    doc.SaveToFile("8361FromHTML.pdf");
                    doc.Close();

If the issue still persists, please provide us your URL to help us do an investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Aug 18, 2016 9:44 am

Thank you very much, it solved now, the point is i was missing this line..
Code: Select all
settings.Size = new SizeF(2000, 1100);

Ghouri0007
 
Posts: 6
Joined: Wed Aug 17, 2016 12:48 pm

Thu Aug 18, 2016 12:05 pm

there is a printing issue here ,if i set custom size then it wont print properly rather out of page print and if i save the file and later open in PDF viewer and print its fine, but default print command wont work well, below I am attaching properties both for custom and default page settings.

Can we manage to print well in default behavior, rather to reopen in viewer and print?

Ghouri0007
 
Posts: 6
Joined: Wed Aug 17, 2016 12:48 pm

Fri Aug 19, 2016 2:34 am

Dear Ghouri0007,

Thanks for your feedback.
Please try to print the document after saving it, like this
Code: Select all
                    doc.SaveToFile("8361FromHTML.pdf");
                    doc.PrintDocument.Print();

If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Fri Aug 19, 2016 5:15 am

Thanks it worked , printing after saving the document, but is there any way that we can convert InnerHtml of a page to PDF , directly, because some sites have secure certificates installed on it, and they demand login before going to any link, I have a web page which i m opening after giving credentials and when inside clicking on any tab and pressing the print button, it send URI which is currently but it prints default page which is login page, not the visible page which is currently opened.

Ghouri0007
 
Posts: 6
Joined: Wed Aug 17, 2016 12:48 pm

Fri Aug 19, 2016 6:08 am

Dear Ghouri0007,

Thanks for your reply.
Sorry that there is no way to do that. Please feel feel to contact us if there is any question.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Fri Aug 19, 2016 6:31 am

so that means, sites having password protected pages wont be converted to PDF?

Ghouri0007
 
Posts: 6
Joined: Wed Aug 17, 2016 12:48 pm

Fri Aug 19, 2016 7:04 am

Dear Ghouri0007,

Sorry that I didn't speak clearly, the page can be converted to PDF, but it doesn't achieve the desired effect you mentioned. It maybe print default page which is login page, not the visible page which is currently opened.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.PDF