HI,
I have a problem with converting HTML to landscape PDF as it converts to with longer width but the content in no spread and stays in the centre. Is there any function to turn on and off or do I need to provide extra element to let it know that it is a landscape conversion
Please be kind enough and provide me a solution
Thank you
@gayan1991
Thank you for contacting support.
Aspose.HTML for .NET API renders the document the way a browser displays it. In case you are noticing some difference then please share source and generated ZIP files along with narrowed down code snippet so that we may investigate further to help you out.
198341.zip (35.7 KB)
Hi @Farhan.Raza ,
I have attached the code snippet with two results (one in HTML & PDF) in png format.
Please let me know the issue behind this
@gayan1991
Would you please also share source HTML document so that we may proceed to assist you.
198341.zip (38.0 KB)
@Farhan.Raza
I have attached documents
@gayan1991
Thank you for sharing requested data.
We have modified your code snippet but exception is being thrown while loading your HTML document with Aspose.PDF for .NET 19.6. Would you please try below code with latest version and share your kind feedback with us.
HtmlLoadOptions options = new HtmlLoadOptions();
options.PageInfo.Margin.Top = 60;
options.PageInfo.Margin.Bottom = 60;
options.PageInfo.Margin.Left = 10;
options.PageInfo.Margin.Right = 10;
//options.PageInfo.IsLandscape = isLandscape;
options.PageInfo.IsLandscape = true;
var fileName = dataDir + "result.html";
string pdfFileName = dataDir + "result_19.6.pdf";
Document document = null;
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(File.ReadAllText(fileName))))
try
{
document = new Document(ms, options);
}
catch (Exception e)
{
AlertFormationHelperEventSource.Current.ReportError(e);
}
try
{
foreach (Page p in document.Pages)
{
p.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
p.PageInfo.Margin.Bottom = 40;
}
document.ProcessParagraphs();
var optimizationOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
optimizationOptions.ImageCompressionOptions.CompressImages = true;
optimizationOptions.ImageCompressionOptions.ImageQuality = 50;
optimizationOptions.LinkDuplcateStreams = true;
optimizationOptions.RemoveUnusedObjects = true;
optimizationOptions.RemoveUnusedStreams = true;
document.OptimizeResources(optimizationOptions);
document.Save(pdfFileName);
}
catch (Exception ex)
{
AlertFormationHelperEventSource.Current.ReportError(ex);
}
Moreover, please note that support is offered via forums only so we are afraid any email address may not be shared. However, your colleague may follow up with us here in this thread.
html content.zip (2.1 KB)
Hi @Farhan.Raza,
We have upgraded the package to 19.6 and it is still the same… I have attached the recent file… please check
@gayan1991
Thank you for sharing the file.
We have attached generated PDF document result2_19.6.pdf while setting page margins to zero. Would you please share a screenshot about your concerns related to this PDF document so that we may assist you accordingly.
Case files.zip (64.9 KB)
Hi @Farhan.Raza,
As I mentioned (if you look previous posts), I have mentioned that my email result is different from PDF generated result. I want my PDF to be generated exactly like email template when I request the PDF to be generated to landscape mood. Please give me a solution as soon as possible. I have attached all the case files related to this case.
Moreover, is the support usually take 12 hours? As I get your reply at night when I am already off from work and I get to see your reply the very next day.
@gayan1991
Please note that Aspose.PDF for .NET API renders HTML the way a browser displays it. Google Chrome and other browsers are displaying your file the way it is rendered in PDF document. In case you want to render it in landscape, you would need to modify source HTML file.
Moreover, we try to reply as soon as possible but the response may take several hours because of investigations into different scenarios and time zone differences.
@Farhan.Raza
So in this case, responsive code will not work for conversion. Is it ? Do I need to provide a that is landscape regardless of screen size? Will the media query work for the conversion?
@gayan1991
We are afraid responsive code may not work during conversion. However, you may share such source file with us so that we may investigate further and log a feature request accordingly. Moreover, the media queries work fine during conversion and you would need to pass a file that is displayed landscape by the browser regardless of screen size.
@Farhan.Raza
I have attached the responsive HTML, it is working google chrome. Please tell why it is not working in conversion. As you have asked I have modified the media query. It is showing the correct input in chrome but not in PDF result
Could the issue be related to quoted-printable? Putting the input coding will make the PDF landscape but it overlaps. Do we need to specify the width?
Case Files 2.zip (65.0 KB)
@gayan1991
We have logged a ticket with ID HTMLNET-2036 in our issue management system for further investigations and we will share our findings with you once some significant updates are available in this regard.
@Farhan.Raza
So far I have tried with HtmlMediaType.Screen for HTMLLoadOptions. Then it starts working with media styles not the encoding i mentioned in my previous message. but please let me know the progress.
@gayan1991
Thank you for the information.
Some of the details about this scenario are now intermixed with several source files. Therefore, would you please rephrase current scenario and your concerns while sharing respective data once again so that we may investigate without any confusion and assist you efficiently.
@Farhan.Raza
The scenario is previously it was changing to landscape mood even though the HTML was written with media queries and responsive in chrome (landscape). Then I put the following line of code and it starts changing.
options.HtmlMediaType = HtmlMediaType.Screen
Now, if i have to change back to portrait mood, i have to remove this line. If the above line stays there, it keeps in landscape. Moreover, even though it is changing to landscape, I always have to specify the width of the PDF. Otherwise, it overlaps.
For more info, look at ‘Case Files 2.zip’ from the previous reply
@gayan1991
Thank you for summing it up.
We have recorded your comments and will further investigate rendering the contents without overlapping while not necessarily needing to set additional options. We will let you know as soon as any further update will be available in this regard.
@gayan1991
We have investigated the ticket and would like to update you that, the HTML document contains media queries which work only in screen media (they look like @media screen), by default we are using print media, so if you do not specify “options.HtmlMediaType = HtmlMediaType.Screen” styles would not apply.
Moreover, overlapping should occur. we have attached file (Rendering comparison.png) which shows how browser (Chrome) and Aspose.HTML render this document, as you can see overlapping occurs in both cases.Rendering comparison.png
However, six gray blocks are wider than they should be. Another ticket with ID HTMLNET-2044 is logged for this. We will let you know as soon as it will be resolved.
HI @Farhan.Raza,
Is there any issue with SVG images when it comes to the conversion from HTML to PDF?