How can I set different page height for only one page in a PDF? [using (Aspose.Pdf.Document)]
In the below code snippet, I’ve created 2 pages (Page curPage and Page chartPage). For the second page, i.e., chartPage, I need to set a height based on some custom logic. So I did create a separate PageInfo pageInfo1() and set the height, but it never worked.
But if I set the height for the first PageInfo object, then it works but it sets that height for ALL the pages.
My requirement is to set a specific height for only one page, i.e., Page chartPage. Please advise or help for a solution.
Document doc = new Document();
Aspose.Pdf.License licensePDF = new Aspose.Pdf.License();
PageInfo pageInfo = doc.PageInfo;
Aspose.Pdf.MarginInfo marginInfo = pageInfo.Margin;
marginInfo.Left = 37;
marginInfo.Right = 37;
marginInfo.Top = 37;
marginInfo.Bottom = 37;
Page curPage = doc.Pages.Add();
Paragraphs paragraphs = curPage.Paragraphs;
Page chartPage = doc.Pages.Add();
chartPage.Paragraphs.Add(textSearchCriteris); //The Original Text Search Criteria Must Be Mentioned
PageInfo pageInfo1 = chartPage.PageInfo;
pageInfo1.Height = 4000;
Thanks
Sree
Hi Sree,
Thanks for your inquiry. Please check the following code snippet to set different page widths for specific pages. You need to render the PDF structure using ProcessParagraphs() to take into account of the PageInfo object. Hopefully, it will help you to accomplish the task.
Document doc = new Document();
PageInfo pageInfo = doc.PageInfo;
Aspose.Pdf.MarginInfo marginInfo = pageInfo.Margin;
marginInfo.Left = 37;
marginInfo.Right = 37;
marginInfo.Top = 37;
marginInfo.Bottom = 37;
// Added page.
Page curPage = doc.Pages.Add();
curPage.Paragraphs.Add(new TextFragment("test page 1"));
// Add the table into the paragraphs collection of section
Aspose.Pdf.Paragraphs paragraphs = curPage.Paragraphs;
// Add content/data for the page
doc.ProcessParagraphs();
// Added New page.
Page chartPage = doc.Pages.Add();
PageInfo pageInfo1 = chartPage.PageInfo;
pageInfo1.Height = 4000;
// add text fragment to paragraphs collection of Page object
chartPage.Paragraphs.Add(new TextFragment("test page 2"));
doc.ProcessParagraphs();
// Added New page.
Page thirdPage = doc.Pages.Add();
PageInfo thirdpageInfo1 = thirdPage.PageInfo;
thirdpageInfo1.Width = 400;
// add text fragment to paragraphs collection of Page object
thirdPage.Paragraphs.Add(new TextFragment("test page 3"));
doc.Save(myDir + "pagewidths.pdf");
Please feel free to contact us for any further assistance.
Best Regards,
Tried the code you have given, Am I missing any reference ? ( My assembly versions : Run-time version v4.0.30319, ver. 9.4.0.0 )
'Aspose.Pdf.Document' does not contain a definition for 'ProcessParagraphs' and no extension method 'ProcessParagraphs' accepting a first argument of type 'Aspose.Pdf.Document' could be found (are you missing a using directive or an assembly reference?
Hi Sree,
Thanks for your feedback. You need to download and use latest version of Aspose.Pdf for .NET, it will help you to accomplish your requirements. As we have recently introduced ProcessParagraphs() method to render PDF structure dynamically, previously API rendered PDF structure with Save() method.
Please feel free to contact us for any further assistance.
Best Regards,