We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Save PDF as PDF

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

Hi Patrick,


Thanks for contacting support.

I have tested the scenario where I have converted a sample PPT file to PDF format using MS PowerPoint 2013 and when I have tried placing a table inside it using Aspose.Pdf for .NET 17.3.0, the process is completed within 4 seconds. The input file is 2.3 MB. Can you please share your input files, so that we can again test the scenario in our environment. We are sorry for this inconvenience.

[C#]

Document pdfDocument = new Document(“c:/pdftest/input.pdf”);<o:p></o:p>

// Get particular page

Page pdfPage = (Page)pdfDocument.Pages[1];

// Create a table

Table table = new Table();

// Set the table border color as LightGray

Aspose.Pdf.Color baseColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(0, 0, 40, 160));

table.DefaultCellTextState.ForegroundColor = Aspose.Pdf.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, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

table.BackgroundColor = Aspose.Pdf.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 = 100;

table.Left = 100;

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("c:/pdftest/TableAdded.pdf");

Hi

Did you see my private message with the files?
regards
patrick

Hi Patrick,


Thanks for sharing the sample files.

I have tested the scenario using both documents where I have used latest release of Aspose.Pdf for .NET 17.3.0 in Visual Studio 2015 running over Windows 10 where I have used Intel Core i5 2.3 Ghz with 16 GB of RAM and as per my observations, the table is added in 2.2 seconds when I have used above stated code with login Portal.pdf file and the process is completed in 2.8 seconds when I have used the same code snippet for BUG_20161116_PR_LBTA-Info-für-PBI_IP-pix.pdf document.

Can you please try using the latest release and in case you still face any issue, please share some details regarding your working environment. We are sorry for your inconvenience.