Hello,
If I open file “Page Break Test.html” in Google Chrome I shared for you in this ticket, I can see page breacks. As result, I can see 3 different pages in Chrome.
But, if I try use Aspose.Words to convert this file to PDF, output PDF file contains only one page, that contains all contents of the source document.
My code snippet is below. Could you please assist?
Mikhael
Page Break Test.zip (476 Bytes)
Dim sSrcFile = “C:\Users\email\Desktop\Gavin Webb\9\Page Break Test.html”
Dim sOutFile = “C:\Out\html 2 pdf.pdf”
Dim doc = New Document(sSrcFile, New Aspose.Words.Loading.HtmlLoadOptions())
doc.Save(sOutFile)
@Mikhael
Cause
The issue you’re experiencing with Aspose.Words converting your HTML file to a single PDF page instead of multiple pages is likely due to the handling of page breaks in the HTML content. Aspose.Words may not be interpreting the page breaks as intended during the conversion process.
Solution
To ensure that page breaks are recognized and respected during the conversion, you can utilize the HtmlLoadOptions
class to specify how the HTML content should be loaded. Specifically, you can set the PageBreaks
option to ensure that page breaks are correctly interpreted.
Code
Here’s an updated version of your code snippet that includes the HtmlLoadOptions
with the necessary settings:
Dim sSrcFile As String = "C:\Users\email\Desktop\Gavin Webb\9\Page Break Test.html"
Dim sOutFile As String = "C:\Out\html 2 pdf.pdf"
Dim options As New Aspose.Words.Loading.HtmlLoadOptions()
options.PageBreaks = True ' Ensure page breaks are recognized
Dim doc As New Document(sSrcFile, options)
doc.Save(sOutFile)
Next Steps
- Implement the updated code and run the conversion again.
- Check the output PDF to see if the page breaks are now respected.
- If the issue persists, review the HTML content to ensure that the page breaks are correctly defined. You may also want to test with different HTML files to isolate the issue.
Please let me know if you need further assistance!
It seems, that “Aspose.Words.Loading.HtmlLoadOptions” has no “PageBreaks” feature. Please look at the screenshot image below.
@Mikhael I checked the latest version 25.7 and couldn’t find the problem. Here is my conclusion:
output.pdf (16.1 KB)
Hello @vyacheslav.deryushev ,
PDF file you sent me contains only 1 opage.
Did you have any chance to open “Page Break Test.html” I shared for your team in my 1-st message in this ticket in Google Chrome? Just click “Ctrl+P” to see print preview. I attached the screenshot image to save your time.
Mikhael
@Mikhael Thanks for the additional information. Yes, I can see your document, but unfortunately Aspose.Words as MS Word cannot give the same result as the print option in the browser.