![]() |
||||||||||||
|
PDF Tools for .NET Usage ExamplesHere are some examples of the PDF command line tools in action, using C# syntax. VB.NET syntax is similar. This is just a small selection—for more examples, see the Full PDF Manual. To see the same examples using the Command Line Tools, click here.Index
1. Basic Usage 1. Basic Usage
Pdf.pdfdoc pdf = Cpdflib.FromFile("in.pdf"); Read in.pdf, select pages 1, 2, 3 and 6, and write those pages to out.pdf. Pdfdoc.pdf evenpdf = Cpdflib.SelectPages(pdf, Cpdflib.Even(Cpdflib.All(pdf))); Select the even pages (2, 4, 6...) from a pre-existing PDF. 2. Merging and Splitting
Pdf.pdfdoc [] pdfs = { pdf1, pdf2 }; Merge pdf1 and pdf2 into one document, pdf. Pdf.pdfdoc [] pdfs = Cpdflib.SplitOnBookmarks(pdf, 0); Split pdf on bookmark boundaries. 3. PagesCpdflib.ScalePages(pdf, Cpdflib.All(pdf), 2.0, 2.0); Scale both the dimensions and contents of pdf by a factor of two in x and y directions. Cpdflib.ScaleToFit(pdf, Cpdflib.All(pdf), Cpdflib.usletterportrait); Scale the pages in pdf to fit the US Letter page size. Cpdflib.ShiftPageContents(pdf, Cpdflib.All(pdf), 26.0, Cpdflib.PtOfMm(18.0)); Shift the contents of the page by 26 pts in the x direction, and 18 millimetres in the y direction. Cpdflib.RotateContents(pdf, Cpdflib.All(pdf), 90.0); Rotate the contents of the pages in in.pdf by ninety degrees and write to out.pdf. Cpdflib.SetCropping(pdf, Cpdflib.All(pdf), 0.0, 0.0, 600.0, 400.0); Crop the pages in pdf to a 600 pts by 400 pts rectangle. 4. Encryption and Decryption
Pdfcrypt.permissions[] permissions = Encrypt pdf using 128bit PDF encryption using the user password fred and the owner password joe, setting some permissions and writing the encrypted file to out.pdf Pdf.pdfdoc pdf = Cpdflib.FromFileDecrypt("in.pdf", "fred"); Load and decrypt a file using the owner password. 5. CompressionCpdflib.Compress(pdf); Compress the data streams in pdf. Cpdflib.Decompress(pdf); Decompress the data streams in pdf. 6. BookmarksPdfmarks.bookmark [] marks = Cpdflib.GetBookmarks(pdf); List the bookmarks in a pdf.
Pdfmarks.bookmark [] marks = 7. Presentations
Cpdflib.AddPresentation Use the Blinds style to build a presentation from the pdf (See manual for full details of each argument). 8. Logos, Watermarks and StampsCpdflib.StampOn(sourcepdf, pdf, Cpdflib.All(pdf)) Stamp the document sourcepdf on to each page of pdf.
Cpdflib.AddText Add a red page number and date to all the pages in pdf using the Courier font at 24pt. 9. Multipage FacilitiesCpdflib.TwoUp(pdf); Two up impose a document.
int[] range = {1, 3, 4}; Add extra blank pages after pages one, three and four of a document. 10. AnnotationsCpdflib.annotation [] annots = Cpdflib.ListAnnotations(pdf); List the annotations in a file pdf Cpdflib.CopyAnnotations(source_pdf, target_pdf); Copy the annotations from source_pdf to target_pdf. 11. Document Information and MetadataCpdflib.SetTitle(pdf, "The New Title"); Set the document title of pdf. Cpdflib.HideToolbar(pdf); Set the document pdf to open with the Acrobat Viewer's toolbar hidden. Cpdflib.SetMetadataFromFile(pdf, "metadata.xml"); Set the metadata in pdf to the contents of the file metadata.xml. Cpdflib.SetPageLayout(pdf, Cpdflib.layout.TwoColumnRight); Set the document pdf to open in Acrobat Viewer showing two columns of pages, starting on the right. Cpdflib.SetPageMode(pdf, Cpdflib.pagemode.FullScreen) Set the document pdf to open in Acrobat Viewer in full screen mode. 12. File AttachmentsCpdflib.AttachFile(pdf, "sheet.xls"); Attach the file sheet.xls to pdf. Cpdflib.RemoveAttachments(pdf): Remove any attachments from pdf. 13. MiscellaneousCpdf.BlackText(pdf); Blacken all the text in pdf. Cpdf.ThinLines(pdf, Cpdflib.All(pdf), 2.0); Make sure all lines in pdf are at least 2 pts wide. |