Class PdfAnnotation.PdfImportedLink
- Namespace
- iTextSharp.text.pdf
- Assembly
- iTextSharp.LGPLv2.Core.dll
This class processes links from imported pages so that they may be active. The following example code reads a group of files and places them all on the output PDF, four pages in a single page, keeping the links active. String[] files = new String[] {"input1.pdf", "input2.pdf"}; String outputFile = "output.pdf"; int firstPage=1; Document document = new Document(); PdfWriter writer = PdfWriter.GetInstance(document, new FileOutputStream(outputFile)); document.SetPageSize(PageSize.A4); float W = PageSize.A4.GetWidth() / 2; float H = PageSize.A4.GetHeight() / 2; document.Open(); PdfContentByte cb = writer.GetDirectContent(); for (int i = 0; i < files.length; i++) { PdfReader currentReader = new PdfReader(files[i]); currentReader.ConsolidateNamedDestinations(); for (int page = 1; page <= currentReader.GetNumberOfPages(); page++) { PdfImportedPage importedPage = writer.GetImportedPage(currentReader, page); float a = 0.5f; float e = (page % 2 == 0) ? W : 0; float f = (page % 4 == 1 || page % 4 == 2) ? H : 0; ArrayList links = currentReader.GetLinks(page); cb.AddTemplate(importedPage, a, 0, 0, a, e, f); for (int j = 0; j < links.Size(); j++) { PdfAnnotation.PdfImportedLink link = (PdfAnnotation.PdfImportedLink)links.Get(j); if (link.IsInternal()) { int dPage = link.GetDestinationPage(); int newDestPage = (dPage-1)/4 + firstPage; float ee = (dPage % 2 == 0) ? W : 0; float ff = (dPage % 4 == 1 || dPage % 4 == 2) ? H : 0; link.SetDestinationPage(newDestPage); link.TransformDestination(a, 0, 0, a, ee, ff); } link.TransformRect(a, 0, 0, a, e, f); writer.AddAnnotation(link.CreateAnnotation(writer)); } if (page % 4 == 0) document.NewPage(); } if (i < files.length - 1) document.NewPage(); firstPage += (currentReader.GetNumberOfPages()+3)/4; } document.Close();
public class PdfAnnotation.PdfImportedLink
- Inheritance
-
PdfAnnotation.PdfImportedLink
- Inherited Members
Methods
CreateAnnotation(PdfWriter)
public PdfAnnotation CreateAnnotation(PdfWriter writer)
Parameters
writer
PdfWriter
Returns
GetDestinationPage()
public int GetDestinationPage()
Returns
IsInternal()
public bool IsInternal()
Returns
SetDestinationPage(int)
public void SetDestinationPage(int newPage)
Parameters
newPage
int
ToString()
Returns a String representation of the link. @since 2.1.6
public override string ToString()
Returns
- string
String representation of the imported link
TransformDestination(float, float, float, float, float, float)
public void TransformDestination(float a, float b, float c, float d, float e, float f)
Parameters
TransformRect(float, float, float, float, float, float)
public void TransformRect(float a, float b, float c, float d, float e, float f)