Hi
I have some PDFs which i manipulate (add Tables) and save them again as PDFs
This works fine for PDFs which have been generated from Word.
If i have a PPT, which is saved as PDF, and then try to manipulate it and save it as PDF again, my code is blocking and the memory consumption is getting higher and higher.
Below is the code
private static void ApprovePdf(Document pdfDocument, MetaData document)
{
// Get particular page
Page pdfPage = (Page)pdfDocument.Pages[1];
// Create a table
Table table = new Table();
// Set the table border color as LightGray
Color baseColor = Color.FromRgb(System.Drawing.Color.FromArgb(0, 0, 40, 160));
table.DefaultCellTextState.ForegroundColor = Color.FromRgb(System.Drawing.Color.FromArgb(0, 40, 160));
table.Border = new BorderInfo(BorderSide.All, .5f, baseColor);
// Set the border for table cells
table.DefaultCellBorder = new BorderInfo(BorderSide.All, .5f, Color.FromRgb(System.Drawing.Color.LightGray));
table.BackgroundColor = Color.LightGray;
Row row = table.Rows.Add();
row.Border = new BorderInfo(BorderSide.All, .5f, baseColor);
MarginInfo marginInfo = new MarginInfo
{
Top = 5,
Left = 5,
Bottom = 5
};
row.DefaultCellPadding = marginInfo;
TextState textState = new TextState();
textState.Font = FontRepository.FindFont(“Arial”);
textState.FontSize = 9;
textState.FontStyle = FontStyles.Bold;
Cell cell1 = row.Cells.Add(“Text”, textState);
cell1.ColSpan = 2;
MarginInfo marginInfoLines = new MarginInfo
{
Top = 2,
Left = 5,
Bottom = 2
};
// Add row to table
Row lines = table.Rows.Add();
lines.DefaultCellPadding = marginInfoLines;
TextState textStateLines = new TextState();
textStateLines.Font = FontRepository.FindFont(“Arial”);
textStateLines.FontSize = 7;
// Add table cells
lines.Cells.Add(“Text”);
lines.Cells.Add(“Text”);
// Enter some test
for (int rowCount = 0; rowCount < 2; rowCount++)
{
// Add row to table
Row approver = table.Rows.Add();
approver.DefaultCellPadding = marginInfoLines;
// Add table cells
approver.Cells.Add("", textStateLines);
approver.Cells.Add(“Test”, textStateLines);
}
}
// Add table object to first page of input document
table.Top = document.LabelTop;
table.Left = document.LabelLeft;
pdfPage.Paragraphs.Add(table);
// Check if PDF/A Compliant, than convert to PDF/A
if (pdfDocument.IsPdfaCompliant)
{
pdfDocument.Convert(new MemoryStream(), PdfFormat.PDF_A_2A, ConvertErrorAction.Delete);
}
MemoryStream pdfStream = new MemoryStream();
pdfDocument.Save(pdfStream);
SavePdf(pdfStream, document);
}
The problem is on pdfDocument.Save(pdfStream);
Any Ideas?
Thanks in Advance!
Best regards
patrick