Hi
I’m trying to take a single page PDF, reduce it in size and then insert that page into another PDF but that new PDF page should be full size with the shrunk content on it. Idea is that I may want to add my own pagination footer and want it clear of anything which might already exist at the bottom of the page.
I can shrink the page but the page is still shrunk on the new document so it’s just adding the page to the document rather than adding the page to the page, if that makes sense, see code below and attached pdf page.
static void Main(string[] args)
{
Aspose.Pdf.License pdfLicense = new Aspose.Pdf.License();
pdfLicense.SetLicense("Aspose.Total.lic");
string file = @"C:\temp\lorem.pdf";
var pageDoc = new Aspose.Pdf.Document(file);
var pdfPageHeight = pageDoc.PageInfo.Height;
var pdfPageWidth = pageDoc.PageInfo.Width;
var newPdf = new Document();
newPdf.PageInfo.Margin.Bottom = 50;
newPdf.PageInfo.Margin.Top = 0;
newPdf.PageInfo.Margin.Left = 0;
newPdf.PageInfo.Margin.Right = 0;
newPdf.PageInfo.Height = Aspose.Pdf.PageSize.A4.Height;
newPdf.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;
Aspose.Pdf.Facades.PdfFileEditor pfe = new Aspose.Pdf.Facades.PdfFileEditor();
// Squash the page a bit so we can fit our own footer on
pfe.ResizeContents(pageDoc, Aspose.Pdf.Facades.PdfFileEditor.ContentsResizeParameters.PageResize(pdfPageWidth, pdfPageHeight-50));
newPdf.Pages.Add(pageDoc.Pages);
var pageNumberStamp = new Aspose.Pdf.PageNumberStamp();
pageNumberStamp.Background = false;
pageNumberStamp.BottomMargin = 10;
pageNumberStamp.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
pageNumberStamp.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Arial");
pageNumberStamp.TextState.FontSize = 8;
pageNumberStamp.Format = $"Page 1 of 1";
newPdf.Pages[1].AddStamp(pageNumberStamp);
newPdf.Save(@"C:\temp\newPDF.pdf");
}
As you’ll see the pagination stamp isn’t in a clear area at the bottom which is what I wanted.
Cheers
Si
lorem.pdf (53.2 KB)