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.
Hi Kuna,
any updates?
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!
Hi Kuna,
HtmlLoadOptions htmloptions = new HtmlLoadOptions();<o:p></o:p>
// Load HTML file
Document doc = new Document("aspose.source.html", htmloptions);
// Resize contents of resultant PDF
doc.ProcessParagraphs();
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
doc.Save("aspose.source.pdf");
Hi,
quick update: there is an issue with the code we sent, in function “HasOverflowCotnent”
Hi Kuna,
it’s been almost a week. any updates on this?
Hi Kuna,
Dim _htmlLoadOptions As New
Aspose.Pdf.HtmlLoadOptions()<o:p></o:p>
Dim _sb As New StringBuilder()<o:p></o:p>
Dim _testPath As String = “C:\Users\Home\Downloads\test
(1)\Temp”<o:p></o:p>
‘setup load options<o:p></o:p>
’_htmlLoadOptions.PageInfo.Margin.Right
= 20;<o:p></o:p>
’_htmlLoadOptions.PageInfo.Margin.Left
= 20;<o:p></o:p>
’_htmlLoadOptions.PageInfo.Margin.Top
= 20;<o:p></o:p>
’_htmlLoadOptions.PageInfo.Margin.Bottom
= 20;<o:p></o:p>
'test 1: default conversion<o:p></o:p>
Dim _pdf As New Aspose.Pdf.Document(_testPath &
“test2.html”, _htmlLoadOptions)<o:p></o:p>
_pdf.Save(_testPath & “pdf_default.pdf”,
Aspose.Pdf.SaveFormat.Pdf)<o:p></o:p>
_sb.AppendLine("Test
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”,
Aspose.Pdf.SaveFormat.Pdf)<o:p></o:p>
_sb.AppendLine("Test
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”,
Aspose.Pdf.SaveFormat.Pdf)<o:p></o:p>
_sb.AppendLine("Test
2: " + HasOverflowContent(_pdf))<o:p></o:p>
…
.....
We are sorry for the inconvenience.
Best Regards,
Thanks for your reply.
Hi Kuna,
Hi Kuna,
Hi Kuna,
ksubramaniyam@dymaxium.com: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?
Hi Kuna,