I am evaluating your component for converting HTML to pdf and I require ability to control the page sizes after the HTML has been imported into Aspose. Although an example is not necessary for my question, I would illustrate one scenario where this is needed. Refer to the attached html file and the 3rd page, if this is converted to PDF the 3rd page’s table will be cut off under normal settings.
we have tried many alternatives and seem to have run against walls (bugs or APIs not working as we would expect). Any direction on how to resize certain pages and have the converted HTML content reflow, would be appreciated!
HtmlLoadOptions htmloptions = new HtmlLoadOptions();<o:p></o:p>
// Load HTML file
Document doc = new Document("aspose.source.html", htmloptions);
// Resize contents of resultant PDF
int page_cnt1 = new int[doc.Pages.Count];
for (int i = 0; i < doc.Pages.Count; i++)
page_cnt1[i] = i + 1;
PdfFileEditor pfe = new PdfFileEditor();
pfe.ResizeContents(doc, page_cnt1, PdfFileEditor.ContentsResizeParameters.PageResize(17*72, 11*72));
// Save output as PDF format
quick update: there is an issue with the code we sent, in function “HasOverflowCotnent”
it’s been almost a week. any updates on this?
Dim _htmlLoadOptions As New
Dim _sb As New StringBuilder()<o:p></o:p>
Dim _testPath As String = “C:\Users\Home\Downloads\test
‘setup load options<o:p></o:p>
'test 1: default conversion<o:p></o:p>
Dim _pdf As New Aspose.Pdf.Document(_testPath &
_pdf.Save(_testPath & “pdf_default.pdf”,
1: " + HasOverflowContent(_pdf))<o:p></o:p>
'test 1a: resize to 8x11<o:p></o:p>
_pdf = New Aspose.Pdf.Document(_testPath & “test2.html”, _htmlLoadOptions)<o:p></o:p>
ResizePagesInPlace(_pdf, 8, 11)<o:p></o:p>
_pdf.Save(_testPath & “pdf_1_8x11.pdf”,
1a: " + HasOverflowContent(_pdf))<o:p></o:p>
'test 2: resize to 11x17<o:p></o:p>
_pdf = New Aspose.Pdf.Document(_testPath & “pdf_1_8x11.pdf”)<o:p></o:p>
ResizePagesInPlace(_pdf, 11, 17)<o:p></o:p>
_pdf.Save(_testPath & “pdf_1_11x17.pdf”,
2: " + HasOverflowContent(_pdf))<o:p></o:p>
We are sorry for the inconvenience.
Thanks for your reply.
Thanks for your reply.Now I do understand why your original solution wasn’t working for us. But this solution is not feasible for us for number of reasons as illustrated below. We believe this to be a bug anyway as we do not see why setting margins would impact the conversion process.This doesn’t work for us for the following reasons:1) We need to be able to control margins.2) Page resizing after the conversion is using scaling and things get either stretched or skewed. Not acceptable to us. (Initial page size ends up being 12.21x11.69. Odd size that doesn’t match any paper size and this varies based on content - again not a good thing for PDfs that need to be printed)3) We need to convert 300 page+ documents into PDF and only one or two pages may contain large tables. With this solution, we will always be converting all the pages at the highest width required.With #2, the end result is usually not acceptable from presentation/readability point of view.In any event, there is no need for us to convert all content at a higher page size when 98% of our pages would fit very well on 8.5x11 and would look better in this setting.Our solution to overcome the shortcoming is as follows:1) Start with 8.5x11 page size2) Convert each Section of the HTML to PDF3) Check if the section has overflow content.4) Set the page size to higher5) Repeat step 3-4 for the section till there is no overflow6) Stitch together/merge all the sectional PDFs into one PDF.This ensures that all the HTML is converted to 8.5x11 size and only the sections that overflow get converted at a higher page size. This allows us to convert the pages naturally to a proper paper size that can be printed. This seems a better compromise for us so we can maintain better 1-1 conversion quality (and avoids scaling/distortion issues).It all works well for us as we had mentioned earlier but the “HasOverflowContent” doesn’t work in all cases. It does a decent job with about 80-90% of the cases we have tested but fails in cases like the one we outlined in the code above.Getting passed your solution above, is there a solution to detect content overflows better? Can you suggest how we can fix our HasOverflowContent function?Let’s stick to answering this question with our “HasOverflowContent”, if you can suggest a solution to make it work 100%, we can work out the rest of the logic to convert properly on our end.
Can you let me know if you have any updates?