Hi,
I have been using ASPOSE PDF licensed version, trying to generate pdf for around 700 pages.
Each page represent a project which has information around a project of constructed html content.
It works fine for few project like 50 t0o 60 projects which means of 60 pages.
I fi try to print for larger like 500 or 600, doesn’t throw any error or exception or printing the pdf also this is not consistent, meaning something it prints all 700 pages, sometimes not with the same data. We can’t say the html or data issue, since sometime it prints well with same data, sometimes not.
I tried multiple ways to figure out, like below different approached/options,
- Each page as separate document and merged at the end to single file,
- Stored in memory as memorystream object
- Each page object and added it to final document as pages
- Finally Saved each file as pdf in temp location, then merged all the file to single file. (in this approach i found sometimes its get stuck with creating a pdf with 0kb and stuck there, its not same file all the time, different files, neither throws error nor doing anything)
Struggling with this issue for more than 3 weeks.
@Sendil.M
You are generating large PDFs (up to 700 pages) using HTML fragments with Aspose.PDF, and experiencing inconsistent behavior—sometimes rendering all pages, sometimes not, with occasional 0KB file creation . This could be related to performance limitations when processing large volumes of HTML content .
Here’s how to approach this:
-
Batch Processing: Instead of generating the entire PDF in one go, break the process into smaller batches (e.g., 50–100 pages at a time). Process each batch separately and merge them afterward. This helps manage memory usage and reduces the chance of timeouts or incomplete renders .
-
Memory Management: Ensure sufficient memory allocation for your application, especially when dealing with large HTML content. Monitor memory usage during generation and consider increasing the heap size if running in a constrained environment .
-
Optimize HTML Fragments: Simplify or minimize the complexity of HTML used in fragments. Avoid inline styles, excessive CSS, or JavaScript where possible, as these can increase processing time and memory consumption .
-
Use Asynchronous Operations: If applicable, implement asynchronous processing to prevent blocking the main thread and improve responsiveness during long-running operations .
-
Check for Known Issues: Review Aspose’s release notes or support forums for any known bugs related to HTML fragment rendering in large documents, such as PDFNET-44828 mentioned in one discussion .
If none of these steps resolve the issue, it may be a limitation or bug in the current version of Aspose.PDF. Please provide a minimal reproducible example so we can investigate further.
A support engineer will follow up in this thread if needed.
I really appreciate your response,
Below is the code used, please let me know about Batch Processing and Memory Management , I don’t see any memory spike too
I dont have big html, below is the html and code used
public PageCollection BuildEmptyProjectDocumentPages(object p)
{
var htmlContent = $@"
<!DOCTYPE html>
<html lang=""en"">
<head>
<meta charset=""utf-8"">
<meta name=""viewport"" content=""width=device-width, initial-scale=1"">
<title>Project {(p.ProjectNumber)} Summary</title>
<style>
html, body {{
background: #FFFFFF;
color: #222222;
font-family: Arial, Helvetica, sans-serif;;
font-size: 12pt;
line-height: 1.45;
margin: 0;
padding: 0;
}}
.page {{
width: 100%;
max-width: 7.5in;
margin: 0 auto;
box-sizing: border-box;
}}
header {{
border-bottom: 2px solid #0B5AA2;
margin-bottom: 16px;
padding-bottom: 8px;
}}
header .title {{
font-size: 22pt;
font-weight: 600;
color:#0B5AA2;
}}
.section {{
margin-top: 18px;
}}
.section h2 {{
font-size: 14pt;
margin: 0 0 8px 0;
color:#0B5AA2;
border-bottom: 1px solid #D9D9D9;
padding-bottom: 4px;
}}
</style>
</head>
<body>
<div class=""page"">
<header>
<div class=""title"">{E(p.ProjectNumber ?? "N/A")} Project Summary</div>
</header>
<div class=""section"">
<h2>No data available for this project!</h2>
</div>
</div>
</body>
</html>
";
var htmlFragment = new HtmlFragment(htmlContent);
page.Paragraphs.Add(htmlFragment);
var header = new TextStamp(p.ProjectNumber)
{
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Center,
RightMargin = 45,
TopMargin = 25,
};
header.TextState.ForegroundColor = Color.Navy;
header.TextState.FontSize = 10;
var pageNoStamp = new PageNumberStamp()
{
RightMargin = 6,
BottomMargin = 15,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Bottom,
StartingNumber = 1,
Format = "- # -"
};
foreach (Page pg in document.Pages)
{
pg.AddStamp(header);
pg.AddStamp(pageNoStamp);
}
return document.Pages;
}
Below code generates 700 pages in loop
var finalDoc = new Document();
foreach (var project in projectResults)
{
var pages = BuildEmptyProjectDocumentPages(project)
finalDoc.Pages.Add(pages);
}
// Save to a temporary file instead of a MemoryStream
string tempPath = Path.Combine(Path.GetTempPath(), $"merged_{Guid.NewGuid()}.pdf");
finalDoc.Save(tempPath);
@Sendil.M
You are generating a large PDF (up to 700 pages) using HTML fragments with Aspose.PDF, and experiencing inconsistent rendering—sometimes all pages render, sometimes not, and occasionally 0KB files are created . Your current approach adds pages one by one into a single document, which can lead to memory pressure and instability .
To improve performance and stability:
- Process in Batches: Break the generation into smaller batches (e.g., 50–100 pages at a time), generate each batch as a separate document, and then merge them .
- Optimize HTML Fragments: Simplify the HTML and CSS used in fragments. Avoid inline styles and excessive CSS rules that may increase processing overhead .
- Monitor Memory Usage: Ensure your application has enough memory allocated, especially when handling large documents. Consider increasing the heap size if needed .
Try implementing these changes and let us know if the issue persists. A support engineer will follow up in this thread if needed.
I’m generating only one page at a time, and merging all the generated PDF at the end, while generating one pdf sometime it fails meaning stuck no exception or error, I’m running this in Azure and no memory related issues i think.
@Sendil.M
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-61625
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
will I get notified if any update made related to this?
@Sendil.M
Yes, we will notify you via this forum thread as soon as some progress is made in this regard.
1 Like