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

Free Support Forum - aspose.com

Page size small when creating PDF from ppt

I am creating pdf from a ppt and a word file and then adding a watermark to the pdf at the bottom left corner (a circle of 5mm radius and margins x: 10mm and y:7mm)
The circle is not visible in the watermarked pdf created from a ppt (as the page size is very small than A4 and the coordinates are out of visibility) But the same watermark is visible in the pdf created from the word file. Attached both sample files for reference.

Following is the code that does the watermarking:

page.PageInfo.Margin = new Aspose.Pdf.MarginInfo() { Bottom = 0, Left = 0, Right = 0, Top = 0 };
// Create Graph instance
Aspose.Pdf.Drawing.Graph graph_Y = new Aspose.Pdf.Drawing.Graph((float)(page.PageInfo.Width), (float)page.PageInfo.Height);
// Add graph object to paragraphs collection of page instance
page.Paragraphs.Add(graph_Y);
Aspose.Pdf.Drawing.Circle circ_Y = new Aspose.Pdf.Drawing.Circle(28.3465f, 19.8425f, 7.086625f);
// Specify fill color for Graph object
circ_Y.GraphInfo.Color = Aspose.Pdf.Color.Red;
// Add Text into Circle
circ_Y.Text = new Aspose.Pdf.Text.TextFragment(“Y”);
//Text color should be in RED color
circ_Y.Text.TextState.ForegroundColor = Aspose.Pdf.Color.Red;
// Add Circle object to shapes collection of Graph object
graph_Y.Shapes.Add(circ_Y);WORD to PDF.pdf (23.4 KB)
PPT to PDF - No WM.pdf (82.8 KB)

Note: I have tried setting the page size by pptDoc.SlideSize.Type = Aspose.Slides.SlideSizeType.A4Paper before saving the presentation to pdf but that doesn’t do anything to the page size.

Any help is appreciated!

Thanks
PradnyaR

@PradnyaR

Thanks for contacting support and sorry for the delayed response.

We have investigated the scenario in our environment and found that API was returning incorrect width and height of the PDF page (i.e (842, 595)), so the graph of these width and height was being added in the PDF, and was not visible in the output. After viewing height and width in Adobe Reader, it was observed the actual width/height was (959.76, 540) and replacing the height and width of the graph inside code, resolved the issue as well.

Please check following graph initialization, which have resolved the issue.

// Create Graph instance
Aspose.Pdf.Drawing.Graph graph_Y = new Aspose.Pdf.Drawing.Graph(959.76f, 540);

Furthermore, we have also logged an investigation ticket as PDFNET-43297 in our issue tracking system, regarding API returning incorrect width/height. We will further look into the details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for this inconvenience.

PPT to PDF - No WM_out.pdf (83.3 KB)

PS: For your reference, we have attached an output generated over our end as well.

@PradnyaR

We have further investigated the document (PPT to PDF - No WM.pdf) and found that the page inside the PDF has a rotation angle set. So in order to get exact/correct width and height of the page, you need to use page.GetPageRect(true) method and final code snippet to add Graph at desired location would be as follows:

Document doc = new Document(dataDir + "PPT to PDF - No WM.pdf");
Page page = doc.Pages[1];
var rect = page.GetPageRect(true);
var height = rect.Height;
var width = rect.Width;
page.PageInfo.Margin = new Aspose.Pdf.MarginInfo() { Bottom = 0, Left = 0, Right = 0, Top = 0 };
// Create Graph instance
Aspose.Pdf.Drawing.Graph graph_Y = new Aspose.Pdf.Drawing.Graph((float)width, (float)height);
graph_Y.Margin = new Aspose.Pdf.MarginInfo() { Bottom = 0, Left = 0, Right = 0, Top = 0 };
// Add graph object to paragraphs collection of page instance
page.Paragraphs.Add(graph_Y);
Aspose.Pdf.Drawing.Circle circ_Y = new Aspose.Pdf.Drawing.Circle(28.3465f, 19.8425f, 7.086625f);
// Specify fill color for Graph object
circ_Y.GraphInfo.Color = Aspose.Pdf.Color.Red;
// Add Text into Circle
circ_Y.Text = new Aspose.Pdf.Text.TextFragment("Y");
//Text color should be in RED color
circ_Y.Text.TextState.ForegroundColor = Aspose.Pdf.Color.Red;
// Add Circle object to shapes collection of Graph object
graph_Y.Shapes.Add(circ_Y);
doc.Save(dataDir + "PPT to PDF - No WM_out.pdf");

In case if you still face any issue, please feel free to let us know.

@asad.ali

Thanks for your response. By adding the following patch related to page.GetPageRect(true); it worked as expected for the PPT->PDF

var rect = page.GetPageRect(true);
var height = rect.Height;
var width = rect.Width;
// Create Graph instance
Aspose.Pdf.Drawing.Graph graph_Y = new Aspose.Pdf.Drawing.Graph((float)width, (float)height);

But the same code is used to stamp the pdf generated from Word and in this case, the doc.save(“dataDir + “Word to PDF.pdf””); HANGS. (the same works fine for word, if I remove the patch related to page.GetPageRect(true); )

Would you be able help on this. Thanks.

@PradnyaR

Thanks for writing back.

We have found that the code kept executing when the width/height value(s) were lengthy after decimal point so when we tried using Math.Ceiling(…) method, the code generated correct output in case of both PDFs. Please check following code snippet which we have used and an attached output, generated over our end.

Document doc = new Document(dataDir + "PPT to PDF - No WM.pdf");
Page page = doc.Pages[1];
var rect = page.GetPageRect(true);
var height = Math.Ceiling(rect.Height);
var width = Math.Ceiling(rect.Width);
page.PageInfo.Margin = new Aspose.Pdf.MarginInfo() { Bottom = 0, Left = 0, Right = 0, Top = 0 };
// Create Graph instance
Aspose.Pdf.Drawing.Graph graph_Y = new Aspose.Pdf.Drawing.Graph((float)width, (float)height); 
...........................
...........................

WORD to PDF_out.pdf (23.9 KB)

In case of any further assistance, please feel free to contact us.