Page Break in existing PDF
Contents
[
Hide
]
As a default layout, the contents inside PDF files are added in Top-Left to Bottom-Right layout. Once the contents exceed beyond page bottom margin, the page break occurs. However you may come across a requirement to insert page break depending upon requirement. A method named AddPageBreak(…) method is added in PdfFileEditor class to accomplish this requirement.)
- public void AddPageBreak(Document src, Document dest, PageBreak[] pageBreaks).
- public void AddPageBreak(string src, string dest, PageBreak[] pageBreaks).
- public void AddPageBreak(Stream src, Stream dest, PageBreak[] pageBreaks).
- src is source document/path to document/stream with source document.
- dest is destination document/path where document will be saved/stream where document will be saved.
- PageBreak is array of page break objects. It have two properties: index of page where page break must be placed and vertical position of the page break on the page.
Example 1 (Add page break)
public static void PageBrakeExample01()
{
// Instantiate Document instance
Document document = new Document(dataDir + "Sample-Document-01.pdf");
// Instantiate blank Document instance
Document dest = new Document();
// Create PdfFileEditor object
PdfFileEditor fileEditor = new PdfFileEditor();
fileEditor.AddPageBreak(document, dest, new PdfFileEditor.PageBreak[]
{
new PdfFileEditor.PageBreak(1, 450)
});
// Save resultant file
dest.Save(dataDir + "PageBreak_out.pdf");
}
Example 2
public static void PageBrakeExample02()
{
// Create PdfFileEditor object
PdfFileEditor fileEditor = new PdfFileEditor();
fileEditor.AddPageBreak(dataDir + "Sample-Document-02.pdf",
dataDir + "PageBreakWithDestPath_out.pdf",
new PdfFileEditor.PageBreak[]
{
new PdfFileEditor.PageBreak(1, 450)
});
}
Example 3
public static void PageBrakeExample03()
{
using (Stream src = new FileStream(dataDir + "Sample-Document-03.pdf", FileMode.Open, FileAccess.Read))
{
using (Stream dest = new FileStream(dataDir + "PageBreakWithStream_out.pdf", FileMode.Create, FileAccess.ReadWrite))
{
PdfFileEditor fileEditor = new PdfFileEditor();
fileEditor.AddPageBreak(src, dest,
new PdfFileEditor.PageBreak[]
{
new PdfFileEditor.PageBreak(1, 450)
});
}
}
}