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

Free Support Forum - aspose.com

Header footer problem after changing size of Page

Hello,
I am facing problem that when size of page is A4 header footer work fine.

But when I change size of paper to letter or legal Header goes outside of the page or space is left blank on top of the header.

Could you please provide source code for different sizes and its output with header and footer.

Hi There,


Thanks for contacting support.

You can resize page contents to avoid this. Please see following code snippet for changing the page size and then resizing the page contents. It will keep header intact. I have attached PDF files for your reference.

C#

Document pdfDocument = new Document(dataDir + “pdf-sample11.pdf”);
PdfFileEditor pfe = new PdfFileEditor();
//Specify Parameter to be used for resizing
PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(
//left margin = 10% of page width
PdfFileEditor.ContentsResizeValue.Units(0),
//new contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%)
PdfFileEditor.ContentsResizeValue.Units(Aspose.Pdf.PageSize.A3.Width),
//right margin is 10% of page
PdfFileEditor.ContentsResizeValue.Units(0),
//top margin = 10% of height
PdfFileEditor.ContentsResizeValue.Units(0),
//new contents height is calculated automatically (similar to width)
PdfFileEditor.ContentsResizeValue.Units(Aspose.Pdf.PageSize.A3.Height),
//bottom margin is 10%
PdfFileEditor.ContentsResizeValue.Units(0)
);
pfe.ResizeContents(pdfDocument, new int[] { 1 } , parameters);

pdfDocument.Save(dataDir + “resized1.pdf”);

If you still face any issue, please feel free to contact us.

Best Regards,

Hello Fahad,

I am using following code snippet to change size of document. But outpout is not as expected could you please check attached documents and code.







static void Main()

{





FileStream fs = new FileStream("…/…/license/Aspose.Pdf.lic", FileMode.Open);

License lic = new License();

lic.SetLicense(fs);



LatexLoadOptions load = new LatexLoadOptions();



Document doc = new Document("…/…/LatexDocs/English/General.tex",load);

doc = SetHeaderFooter(doc);



doc.Save("…/…/output/General.pdf");

doc=ChangeSize(doc, 1);



doc.Save("…/…/output/General_resized.pdf");



}



static Document ChangeSize(Document doc, int pageType)

{



PdfFileEditor pfe = new PdfFileEditor();



if (pageType == 1)

{



PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(PdfFileEditor.ContentsResizeValue.Units(0),

PdfFileEditor.ContentsResizeValue.Units(Aspose.Pdf.PageSize.PageLetter.Width),

PdfFileEditor.ContentsResizeValue.Units(0),

PdfFileEditor.ContentsResizeValue.Units(0),

PdfFileEditor.ContentsResizeValue.Units(Aspose.Pdf.PageSize.PageLetter.Height),

PdfFileEditor.ContentsResizeValue.Units(0)

);

pfe.ResizeContents(doc, new int[] { 1 }, parameters);

}

else if (pageType == 2)

{

PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(PdfFileEditor.ContentsResizeValue.Units(0),

PdfFileEditor.ContentsResizeValue.Units(Aspose.Pdf.PageSize.PageLegal.Width),

PdfFileEditor.ContentsResizeValue.Units(0),

PdfFileEditor.ContentsResizeValue.Units(0),

PdfFileEditor.ContentsResizeValue.Units(Aspose.Pdf.PageSize.PageLegal.Height),

PdfFileEditor.ContentsResizeValue.Units(0)

);

pfe.ResizeContents(doc, new int[] { 1 }, parameters);

}

return doc;

}



static Document SetHeaderFooter(Document doc)

{

Table tab = new Table {ColumnWidths = “50% 50%”};

tab.DefaultCellPadding=new MarginInfo(5,5,5,5);

tab.Border=new BorderInfo(BorderSide.Bottom,0.1f);

for (int i = 0; i
{

Row r1=tab.Rows.Add();

r1.Cells.Add(“Header”);

r1.Cells.Add(“Header”);

}

foreach (Page page in doc.Pages)

{

page.Header = new HeaderFooter();

page.Header.Margin.Top = 10;



page.Header.Paragraphs.Add(tab);

}

return doc;

}

Hello Fahad,
And in the same document could you please help me with another issue, that is line is breaking on page even if the space is avaliable on the page. When document loaded through latex.

Hello Sameer,

Thanks for sharing further details.

I have tested the scenario using your provided General.pdf file and have managed to resize the PDF file to page size Legal correctly using Aspose.Pdf for .NET 17.4.0. I have attached the PDF file for your reference and I have attached the Document Properties screen shot also for your reference.

If you still face issues, please share your environment details to reproduce the issue at our end.

We are sorry for this inconvenience.

Best Regards,

Hi Sameer,


Hello Fahad, And in the same document could you please help me with another issue, that is line is breaking on page even if the space is available on the page. When document loaded through latex.

I have tested the scenario and have managed to reproduce the issue that while converting latex to PDF, in the resultant PDF file line is breaking on page even if the space is available on the page. For the sake of correction, I have logged a ticket PDFNET-42658 in our issue tracking system. We will further look into the details of this issue and will keep you updated on the status of its resolution within this forum thread. Please be patient and spare us little time.

We are sorry for this inconvenience.

Best Regards,

Hello Fahad,

Could you please provide me the code for resizing the content to LETTER and LEGAL as well,

I have attached screenshot of document properties, generated by above code which I shared with you in above post.



Thank you,

Hi Sameer,


Thanks for your inquiry.

In order to change the page size to Legal or Letter, please check following code snippet.

Document doc = new Document(dataDir + “input.pdf”);<o:p></o:p>

foreach(Page p in doc.Pages)

{

// Set the page size as Letter (11.0 x 8.5 in) and in Aspose.Pdf, 1 inch = 72 points

// So Letter dimensions in points will be (792 x 612)

p.SetPageSize(612, 792);

// Set the page size as Legal (14.0 x 8.5 in) and in Aspose.Pdf, 1 inch = 72 points

// So Legal dimensions in points will be (1008 x 612)

p.SetPageSize(612, 1008);

}

doc.Save(dataDir + "output.pdf");


Moreover please note that, after changing the dimensions of the page, it is quite possible that some content might not fit on the page due to change height and width. However you can adjust content according to page new height and width by following guidelines given over "Fitting the Page Content to New Page Orientation" article. In case of any further assistance, please let us know.


Best Regards,