when i am converting Html to Pdf content is cutting in right side for all pages. If content is more width. I need fit the content to pdf pages if html page is more width. I have attached the example pdf.
can you suggest me how to solve the issueExport Report (28).pdf (153.0 KB)
Would you please share your sample HTML in .zip format along with the code snippet that you are using for conversion? We will test the scenario in our environment and address it accordingly.
Here is the code snippet
var html = GetContentFromUrlAsStream(documentUrl);
string rootDir = AppDomain.CurrentDomain.BaseDirectory;
HtmlLoadOptions loadOptions = new HtmlLoadOptions()
{
IsEmbedFonts = true,
PageLayoutOption = HtmlPageLayoutOption.FitToWidestContentWidth,
};
Aspose.Pdf.Document pdfdocument = new Aspose.Pdf.Document(html, loadOptions);
savePdfFile = GetFileNameToSaveInTemp(GetTempFolderPath());
pdfdocument.Save(savePdfFile, Aspose.Pdf.SaveFormat.Pdf);
Private methods
private Stream GetContentFromUrlAsStream(string url, ICredentials credentials = null)
{
using (var handler = new HttpClientHandler { Credentials = credentials })
using (var httpClient = new HttpClient(handler))
{
return httpClient.GetStreamAsync(url).GetAwaiter().GetResult();
}
}
private string GetTempFolderPath(string TempFilesPath = null)
{
// ensure that custom temp folder exists
if (!String.IsNullOrEmpty(TempFilesPath) && !Directory.Exists(TempFilesPath))
{
Directory.CreateDirectory(TempFilesPath);
}
return TempFilesPath ?? Path.GetTempPath();
}
private string GetFileNameToSaveInTemp(string tempPath)
{
var tmpPdfFilePath = Path.Combine(tempPath, "doc" + Path.GetRandomFileName() + ".pdf");
return tmpPdfFilePath;
}