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.

Mon Aug 14, 2017 9:43 pm

Hello.

I convert HTML string to PDF using Spire.pdf.dll. However, when I set margins it cuts the content of page on the right. here is the code that I have. Any suggestions are very much appreciated.

Shared Sub ConvertHtmlToPdf(ByVal strHTML As String, ByVal PdfFileName As String)

Dim pdfDoc As PdfDocument = New PdfDocument
Dim pdfSetting As PdfPageSettings = New PdfPageSettings
Dim pdfFormat As HtmlConverter.PdfHtmlLayoutFormat = New HtmlConverter.PdfHtmlLayoutFormat

pdfDoc.CompressionLevel = PdfCompressionLevel.BestSpeed
pdfDoc.DocumentInformation.Author = "Wespath Benefits and Investments"
pdfDoc.PageScaling = PdfPrintPageScaling.FitSize <--------- I played with all options already

pdfDoc.UseHighQualityImage = True
'pdfFormat.Layout = Graphics.PdfLayoutType.Paginate
pdfFormat.FitToPage = HtmlConverter.Clip.Both
pdfSetting.Size = PdfPageSize.Letter
pdfSetting.Orientation = PdfPageOrientation.Portrait

pdfSetting.Margins.Left = 60
pdfSetting.Margins.Right = 35
pdfSetting.Margins.Top = 35
pdfSetting.Margins.Bottom = 26

pdfDoc.LoadFromHTML(strHTML, True, pdfSetting, pdfFormat)
pdfDoc.SaveToFile(PdfFileName, FileFormat.PDF)
pdfDoc.Close()
End Sub

Tanya Lerner
tlerner@wespath.org

tlerner
 
Posts: 32
Joined: Mon Aug 14, 2017 5:49 pm

Tue Aug 15, 2017 7:21 am

Hello,

Thanks for your inquiry. When you use the method to convert html to pdf, you need to be sure that the pdf page size you set can hold the html content. And there is another method you could try.
https://www.e-iceblue.com/Tutorials/Spi ... lugin.html
In addition, the PageScaling property can only work when print.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Thu Mar 15, 2018 9:53 am

Hi,

I am having the same issue.

If I set a page margin then the content at the bottom is cropped. If I remove the margin all the content appears.

Did you get round to fixing this bug? Or is there a workaround available which doesn't involve downloading the plugins?

Thanks,
Mark

markcraven15
 
Posts: 2
Joined: Thu Mar 15, 2018 9:22 am

Thu Mar 15, 2018 10:23 am

Hello,

Thanks for your post. When using the method(LoadFromHTML) to convert html to pdf, you need to be sure that the pdf page size you set can hold the html content. On the other hand, to help us investigate the issue, please share us with your full code and html file.

Best regards,
Simon
E-icelbue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Mon Mar 19, 2018 6:51 am

Hello,

How is the issue going?
Your feedback will be greatly appreciated.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Thu Mar 22, 2018 9:05 am

I found a work around.

1. Shrink the PDF document by the size of the margins.
2. Make a new PDF document with margins.
3. Insert the first PDF document into the second.

markcraven15
 
Posts: 2
Joined: Thu Mar 15, 2018 9:22 am

Thu Mar 22, 2018 9:42 am

Hello,

Thanks for sharing the workaround. If you encounter any other question, welcome to write to us.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Return to Spire.PDF