Class PdfDocument

java.lang.Object
com.ironsoftware.ironpdf.PdfDocument
All Implemented Interfaces:
Printable

public class PdfDocument extends Object implements Printable
Represents a PDF document. Allows: loading, editing, manipulating, merging, signing printing and saving PDFs.
  • Constructor Details

    • PdfDocument

      public PdfDocument(Path pdfFilePath, String password) throws IOException
      Opens an existing PDF document for editing.
      Parameters:
      pdfFilePath - The PDF file path.
      password - Optional user password if the PDF document is encrypted.
      Throws:
      IOException - if an I/O error occurs reading from the stream
    • PdfDocument

      public PdfDocument(Path pdfFilePath, String password, String ownerPassword) throws IOException
      Opens an existing PDF document for editing.
      Parameters:
      pdfFilePath - The PDF file path.
      password - Optional user password if the PDF document is encrypted.
      ownerPassword - Optional password if the PDF document is protected by owner (printing, modifying restrictions etc..)
      Throws:
      IOException - if an I/O error occurs reading from the stream
    • PdfDocument

      public PdfDocument(byte[] pdfData, String password, String ownerPassword)
      Opens an existing PDF document for editing.
      Parameters:
      pdfData - The PDF file data as byte array.
      password - Optional user password if the PDF document is encrypted.
      ownerPassword - Optional password if the PDF document is protected by owner (printing, modifying restrictions etc..)
    • PdfDocument

      public PdfDocument(Path pdfFilePath) throws IOException
      Opens an existing PDF document for editing.
      Parameters:
      pdfFilePath - The PDF file path.
      Throws:
      IOException - the io exception
    • PdfDocument

      public PdfDocument(byte[] pdfData, String password)
      Opens an existing PDF document for editing.
      Parameters:
      pdfData - The PDF file data as byte array.
      password - Optional user password if the PDF document is encrypted.
    • PdfDocument

      public PdfDocument(byte[] pdfData)
      Opens an existing PDF document for editing.
      Parameters:
      pdfData - The PDF file data as byte array.
  • Method Details

    • fromFile

      public static PdfDocument fromFile(Path pdfFilePath, String password) throws IOException
      Opens an existing PDF document for editing.
      Parameters:
      pdfFilePath - The PDF file path.
      password - Optional user password if the PDF document is encrypted.
      Returns:
      An IronPdf.PdfDocument object as loaded from the file path.
      Throws:
      IOException - if an I/O error occurs reading from the stream
    • fromFile

      public static PdfDocument fromFile(Path pdfFilePath, String password, String ownerPassword) throws IOException
      Opens an existing PDF document for editing.
      Parameters:
      pdfFilePath - The PDF file path.
      password - Optional user password if the PDF document is encrypted.
      ownerPassword - Optional password if the PDF document is protected by owner (printing, modifying restrictions etc..)
      Returns:
      An IronPdf.PdfDocument object as loaded from the file path.
      Throws:
      IOException - if an I/O error occurs reading from the stream
    • fromFile

      public static PdfDocument fromFile(Path pdfFilePath) throws IOException
      Opens an existing PDF document for editing.
      Parameters:
      pdfFilePath - The PDF file path.
      Returns:
      An IronPdf.PdfDocument object as loaded from the file path.
      Throws:
      IOException - if an I/O error occurs reading from the stream
    • fromImage

      public static PdfDocument fromImage(List<Path> imagesPath)
      Converts a single image file to an identical PDF document of matching dimensions.

      The default PaperSize is A4.

      Note: Imaging.ImageBehavior.CropPage will set PaperSize equal to ImageSize.

      Parameters:
      imagesPath - A list of file path of the image file.
      Returns:
      Returns a PdfDocument document which can then be edited, saved or served over the web.
    • fromImage

      public static PdfDocument fromImage(List<Path> imagesPath, PaperSize paperSize)
      Converts a single image file to an identical PDF document of matching dimensions.

      The default PaperSize is A4. You can set it via ImageToPdfConverter.PaperSize.

      Note: Imaging.ImageBehavior.CropPage will set PaperSize equal to ImageSize.

      Parameters:
      imagesPath - A list of file path of the image file.
      paperSize - A target paper size. Default is A4.
      Returns:
      Returns a PdfDocument document which can then be edited, saved or served over the web.
    • fromImage

      public static PdfDocument fromImage(List<Path> imagesPath, ImageBehavior imageBehavior)
      Converts a single image file to an identical PDF document of matching dimensions.

      The default PaperSize is A4.

      Note: Imaging.ImageBehavior.CropPage will set PaperSize equal to ImageSize.

      Parameters:
      imagesPath - A list of file path of the image file.
      imageBehavior - Describes how image should be placed on the PDF page
      Returns:
      Returns a PdfDocument document which can then be edited, saved or served over the web.
    • fromImage

      public static PdfDocument fromImage(List<Path> imagesPath, ImageBehavior imageBehavior, PaperSize paperSize)
      Converts a single image file to an identical PDF document of matching dimensions.

      Note: Imaging.ImageBehavior.CropPage will set PaperSize equal to ImageSize.

      Parameters:
      imagesPath - A list of file path of the image file.
      imageBehavior - Describes how image should be placed on the PDF page.
      paperSize - A target paper size. Default is A4.
      Returns:
      Returns a PdfDocument document which can then be edited, saved or served over the web.
    • fromImage

      public static PdfDocument fromImage(List<Path> imagesPath, ImageBehavior imageBehavior, ChromePdfRenderOptions renderOptions)
      Converts a single image file to an identical PDF document of matching dimensions.

      The default PaperSize is A4. You can set it via ChromePdfRenderOptions.setPaperSize(PaperSize).

      Note: Imaging.ImageBehavior.CropPage will set PaperSize equal to ImageSize.

      Parameters:
      imagesPath - A list of file path of the image file.
      imageBehavior - Describes how image should be placed on the PDF page.
      renderOptions - Rendering options.
      Returns:
      Returns a PdfDocument document which can then be edited, saved or served over the web.
    • getBookmark

      public BookmarkManager getBookmark()
      Gets the BookmarkManager for this PDF document. BookmarkManager allows reading, removing and editing of bookmarks from the PDF outline. *

      See: BookmarkManager.

      Returns:
      the BookmarkManager
    • getMetadata

      public MetadataManager getMetadata()
      Gets the metadata manager for this PDF document. MetadataManager allows metadata such as Author etc. to be read and set.

      See: MetadataManager.

      Returns:
      the MetadataManager
    • getAnnotation

      public AnnotationManager getAnnotation()
      Gets the annotation manager for this PDF document. AnnotationManager allows annotation objects to be edited.

      See: AnnotationManager.

      Returns:
      the AnnotationManager
    • getForm

      public FormManager getForm()
      Gets the form manager for this PDF document. FormManager allows AcroForm fields to be read and set.

      See: FormManager.

      Returns:
      the FormManager
    • getAttachment

      public AttachmentManager getAttachment()
      Gets the attachment manager for this PDF document. AttachmentManager allows attachment objects to be edited.

      See: AttachmentManager.

      Returns:
      the AttachmentManager
    • getSecurity

      public SecurityManager getSecurity()
      Gets security.
      Returns:
      the SecurityManager
    • getSignature

      public SignatureManager getSignature()
      Gets signature.
      Returns:
      the SignatureManager
    • merge

      public static PdfDocument merge(PdfDocument A, PdfDocument B)
      Static method that joins (concatenates) 2 PDF documents together into one PDF document.

      If the second PDF contains form fields, the resulting PDF's form fields will be appended with an origin index number. e.g. 'Name' from the first PDF will become 'Name_0'

      Parameters:
      A - A PDF
      B - A Seconds PDF
      Returns:
      A new, merged PdfDocument
    • merge

      public static PdfDocument merge(List<PdfDocument> Documents)
      Static method that joins (concatenates) 2 PDF documents together into one PDF document.

      If the second PDF contains form fields, the resulting PDF's form fields will be appended with an origin index number. e.g. 'Name' from the first PDF will become 'Name_0'

      Parameters:
      Documents - A List of PdfDocument. To merge existing PDF files you may use the PdfDocument.FromFile static method in conjunction with Merge.
      Returns:
      A new, merged PdfDocument
    • copyPage

      public final PdfDocument copyPage(int PageIndex)
      Creates a new PDF by copying a page from this PdfDocument into a new blank document.
      Parameters:
      PageIndex - Index of the page. Note: Page 1 has index 0...
      Returns:
      A new PdfDocument
    • copyPages

      public final PdfDocument copyPages(Iterable<Integer> PageIndexes)
      Creates a new PDF by copying a page from this PdfDocument into a new blank document.
      Parameters:
      PageIndexes - An IEnumerable of page indexes to copy into the new PDF.
      Returns:
      A new PdfDocument
    • copyPages

      public final PdfDocument copyPages(int StartIndex, int EndIndex)
      Creates a new PDF by copying a range of pages from this PdfDocument into a new blank document.
      Parameters:
      StartIndex - The index of the first PDF page to copy. Note: Page 1 has index 0
      EndIndex - The index of the last PDF page to copy.
      Returns:
      A new PdfDocument
    • appendPdf

      public final PdfDocument appendPdf(PdfDocument AnotherPdfFile)
      Appends another PDF to the end of the current PdfDocument.

      If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will become 'Name_'

      Parameters:
      AnotherPdfFile - PdfDocument to append.
      Returns:
      A new PdfDocument
    • insertPdf

      public final PdfDocument insertPdf(PdfDocument AnotherPdfFile)
      Inserts another PDF into the current PdfDocument, starting at a given Page Index.

      If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'

      Parameters:
      AnotherPdfFile - Another PdfDocument...
      Returns:
      Returns this PdfDocument object, allowing for a 'fluent' chained in-line code style
    • insertPdf

      public final PdfDocument insertPdf(PdfDocument AnotherPdfFile, int AtIndex)
      Inserts another PDF into the current PdfDocument, starting at a given Page Index.

      If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'

      Parameters:
      AnotherPdfFile - Another PdfDocument.
      AtIndex - Index at which to insert the new content. Note: Page 1 has index 0...
      Returns:
      Returns this PdfDocument object, allowing for a 'fluent' chained in-line code style
    • prependPdf

      public final PdfDocument prependPdf(PdfDocument AnotherPdfFile)
      Adds another PDF to the beginning of the current PdfDocument.

      If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'

      Parameters:
      AnotherPdfFile - PdfDocument to prepend.
      Returns:
      Returns this PdfDocument object, allowing for a 'fluent' chained in-line code style
    • removePages

      public final PdfDocument removePages(PageSelection pageSelection)
      Removes a range of pages from the PDF
      Parameters:
      pageSelection - The selected page index(es). Default is all pages.
      Returns:
      Returns this PdfDocument object, allowing for a 'fluent' chained in-line code style
    • getPagesInfo

      public final List<PageInfo> getPagesInfo()
      Gets a list of information about pages in this PDF as a List of PageInfo.
      Returns:
      A list of information about the PDF’s pages.
    • getPagesInfo

      public final Map<Integer,PageInfo> getPagesInfo(PageSelection pageSelection)
      Gets a Map of information a selection of pages in this PDF as a List of PageInfo.
      Parameters:
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      a map of page index and page information.
    • rotateAllPages

      public final void rotateAllPages(PageRotation rotation)
      Rotates all pages of the PdfDocument by a specified number of degrees.
      Parameters:
      rotation - Degrees of rotation. May be 0,90,180 or 270
    • rotatePage

      public final void rotatePage(PageRotation pageRotation, PageSelection pageSelection)
      Rotates a selection page of the PdfDocument by a specified number of degrees.
      Parameters:
      pageRotation - Degrees of rotation. May be 0,90,180 or 270
      pageSelection - Selected page indexes. Default is all pages.
    • resizePage

      public final void resizePage(double pageWidth, double pageHeight, PageSelection pageSelection)
      Resize a page to the specified dimensions (in millimeters)
      Parameters:
      pageWidth - Desired page width, in millimeters
      pageHeight - Desired page height, in millimeters
      pageSelection - Selected page indexes.
    • addBackgroundPdf

      public final PdfDocument addBackgroundPdf(PdfDocument backgroundPdf)
      Adds a background to each page of this PDF. The background is copied from a first page in the backgroundPdf document.
      Parameters:
      backgroundPdf - The background PDF document.
      Returns:
      Returns this PdfDocument object, allowing for a 'fluent' chained in-line code style
    • addBackgroundPdf

      public final PdfDocument addBackgroundPdf(PdfDocument backgroundPdf, int backgroundPdfPageIndex)
      Adds a background to each page of this PDF. The background is copied from a selected page in the backgroundPdf document.
      Parameters:
      backgroundPdf - The background PDF document.
      backgroundPdfPageIndex - Index (zero-based page number) of the page to copy from the Background/Foreground PDF. Default is 0.
      Returns:
      Returns this PdfDocument object, allowing for a 'fluent' chained in-line code style
    • addBackgroundPdf

      public final PdfDocument addBackgroundPdf(PdfDocument backgroundPdf, PageSelection pageSelection)
      Adds a background to selected page(s) of this PDF. The background is copied from a selected page in the backgroundPdf document.
      Parameters:
      backgroundPdf - The background PDF document.
      pageSelection - PageSelection to which the background/foreground will be added. Default is PageSelection.AllPages().
      Returns:
      Returns this PdfDocument object, allowing for a 'fluent' chained in-line code style
    • addBackgroundPdf

      public final PdfDocument addBackgroundPdf(PdfDocument backgroundPdf, int backgroundPdfPageIndex, PageSelection pageSelection)
      Adds a background to selected page(s) of this PDF. The background is copied from a selected page in the backgroundPdf document.
      Parameters:
      backgroundPdf - The background PDF document.
      backgroundPdfPageIndex - Index (zero-based page number) of the page to copy from the Background/Foreground PDF. Default is 0.
      pageSelection - PageSelection to which the background/foreground will be added. Default is PageSelection.AllPages().
      Returns:
      Returns this PdfDocument object, allowing for a 'fluent' chained in-line code style
    • addForegroundPdf

      public final PdfDocument addForegroundPdf(PdfDocument foregroundPdf)
      Adds a foreground to each page of this PDF. The foreground is copied from a first page of the foregroundPdf document.
      Parameters:
      foregroundPdf - The foreground PDF document.
      Returns:
      Returns this PdfDocument object, allowing for a 'fluent' chained in-line code style
    • addForegroundPdf

      public final PdfDocument addForegroundPdf(PdfDocument foregroundPdf, int foregroundPdfPageIndex)
      Adds a foreground to each page of this PDF. The foreground is copied from a selected page in the foregroundPdf document.
      Parameters:
      foregroundPdf - The foreground PDF document.
      foregroundPdfPageIndex - Index (zero-based page number) of the page to copy from the Background/Foreground PDF. Default is 0.
      Returns:
      Returns this PdfDocument object, allowing for a 'fluent' chained in-line code style
    • addForegroundPdf

      public final PdfDocument addForegroundPdf(PdfDocument foregroundPdf, PageSelection pageSelection)
      Adds a foreground to selected page(s) of this PDF. The foreground is copied from a selected page in the foregroundPdf document.
      Parameters:
      foregroundPdf - The foreground PDF document.
      pageSelection - PageSelection to which the background/foreground will be added. Default is PageSelection.AllPages().
      Returns:
      Returns this PdfDocument object, allowing for a 'fluent' chained in-line code style
    • addForegroundPdf

      public final PdfDocument addForegroundPdf(PdfDocument foregroundPdf, int foregroundPdfPageIndex, PageSelection pageSelection)
      Adds a foreground to selected page(s) of this PDF. The foreground is copied from a selected page in the foregroundPdf document.
      Parameters:
      foregroundPdf - The foreground PDF document.
      foregroundPdfPageIndex - Index (zero-based page number) of the page to copy from the Background/Foreground PDF. Default is 0.
      pageSelection - PageSelection to which the background/foreground will be added. Default is PageSelection.AllPages().
      Returns:
      Returns this PdfDocument object, allowing for a 'fluent' chained in-line code style
    • addTextHeader

      public PdfDocument addTextHeader(TextHeaderFooter header)
      Renders TEXT page headers onto an existing PDF File
      Parameters:
      header - A new instance of IronPdf.TextHeaderFooter that defines the header content and layout.
      Returns:
      the pdf document
    • addTextHeader

      public PdfDocument addTextHeader(TextHeaderFooter header, PageSelection pageSelection)
      Renders TEXT page headers onto an existing PDF File
      Parameters:
      header - A new instance of IronPdf.TextHeaderFooter that defines the header content and layout.
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      the pdf document
    • addTextHeader

      public PdfDocument addTextHeader(TextHeaderFooter header, HeaderFooterOptions headerFooterOptions)
      Renders TEXT page headers onto an existing PDF File
      Parameters:
      header - A new instance of IronPdf.TextHeaderFooter that defines the header content and layout.
      headerFooterOptions - HeaderFooterOption.
      Returns:
      the pdf document
    • addTextHeader

      public PdfDocument addTextHeader(TextHeaderFooter header, HeaderFooterOptions headerFooterOptions, PageSelection pageSelection)
      Renders TEXT page headers onto an existing PDF File
      Parameters:
      header - A new instance of IronPdf.TextHeaderFooter that defines the header content and layout.
      headerFooterOptions - HeaderFooterOption.
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      the pdf document
    • addTextFooter

      public PdfDocument addTextFooter(TextHeaderFooter footer)
      Renders TEXT page footers onto an existing PDF File
      Parameters:
      footer - A new instance of IronPdf.TextHeaderFooter that defines the footer content and layout.
      Returns:
      the pdf document
    • addTextFooter

      public PdfDocument addTextFooter(TextHeaderFooter footer, PageSelection pageSelection)
      Renders TEXT page footers onto an existing PDF File
      Parameters:
      footer - A new instance of IronPdf.TextHeaderFooter that defines the footer content and layout.
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      the pdf document
    • addTextFooter

      public PdfDocument addTextFooter(TextHeaderFooter footer, HeaderFooterOptions headerFooterOptions)
      Renders TEXT page footer onto an existing PDF File
      Parameters:
      footer - A new instance of IronPdf.TextHeaderFooter that defines the footer content and layout.
      headerFooterOptions - HeaderFooterOption.
      Returns:
      the pdf document
    • addTextFooter

      public PdfDocument addTextFooter(TextHeaderFooter footer, HeaderFooterOptions headerFooterOptions, PageSelection pageSelection)
      Renders TEXT page footer onto an existing PDF File
      Parameters:
      footer - A new instance of IronPdf.TextHeaderFooter that defines the footer content and layout.
      headerFooterOptions - HeaderFooterOption.
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      the pdf document
    • addHtmlHeader

      public PdfDocument addHtmlHeader(HtmlHeaderFooter header)
      Renders HTML page headers onto an existing PDF File
      Parameters:
      header - A new instance of IronPdf.HtmlHeaderFooter that defines the header content and layout.
      Returns:
      the pdf document
    • addHtmlHeader

      public PdfDocument addHtmlHeader(HtmlHeaderFooter header, PageSelection pageSelection)
      Renders HTML page headers onto an existing PDF File
      Parameters:
      header - A new instance of IronPdf.HtmlHeaderFooter that defines the header content and layout.
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      the pdf document
    • addHtmlHeader

      public PdfDocument addHtmlHeader(HtmlHeaderFooter header, HeaderFooterOptions headerFooterOptions)
      Renders HTML page headers onto an existing PDF File
      Parameters:
      header - A new instance of IronPdf.HtmlHeaderFooter that defines the header content and layout.
      headerFooterOptions - HeaderFooterOption.
      Returns:
      the pdf document
    • addHtmlHeader

      public PdfDocument addHtmlHeader(HtmlHeaderFooter header, HeaderFooterOptions headerFooterOptions, PageSelection pageSelection)
      Renders HTML page headers onto an existing PDF File
      Parameters:
      header - A new instance of IronPdf.HtmlHeaderFooter that defines the header content and layout.
      headerFooterOptions - HeaderFooterOption.
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      the pdf document
    • addHtmlFooter

      public PdfDocument addHtmlFooter(HtmlHeaderFooter footer)
      Renders HTML page footers onto an existing PDF File
      Parameters:
      footer - A new instance of IronPdf.HtmlHeaderFooter that defines the footer content and layout.
      Returns:
      the pdf document
    • addHtmlFooter

      public PdfDocument addHtmlFooter(HtmlHeaderFooter footer, PageSelection pageSelection)
      Renders HTML page footers onto an existing PDF File
      Parameters:
      footer - A new instance of IronPdf.HtmlHeaderFooter that defines the footer content and layout.
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      the pdf document
    • addHtmlFooter

      public PdfDocument addHtmlFooter(HtmlHeaderFooter footer, HeaderFooterOptions headerFooterOptions)
      Renders HTML page footer onto an existing PDF File
      Parameters:
      footer - A new instance of IronPdf.HtmlHeaderFooter that defines the footer content and layout.
      headerFooterOptions - HeaderFooterOption.
      Returns:
      the pdf document
    • addHtmlFooter

      public PdfDocument addHtmlFooter(HtmlHeaderFooter footer, HeaderFooterOptions headerFooterOptions, PageSelection pageSelection)
      Renders HTML page footer onto an existing PDF File
      Parameters:
      footer - A new instance of IronPdf.HtmlHeaderFooter that defines the footer content and layout.
      headerFooterOptions - HeaderFooterOption.
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      the pdf document
    • drawImage

      public final void drawImage(Path imagePath, DrawImageOptions option) throws IOException
      Draws an image onto the PDF document
      Parameters:
      imagePath - The image file path.
      option - the option
      Throws:
      IOException - the io exception
    • drawImage

      public final void drawImage(byte[] imageBytes, DrawImageOptions option)
      Draws an image onto the PDF document
      Parameters:
      imageBytes - image byte array
      option - the option
    • toBufferedImages

      public final List<BufferedImage> toBufferedImages() throws IOException
      Rasterizes (renders) the PDF into BufferedImage objects. 1 BufferedImage for each page.
      Returns:
      An array of BufferedImage objects.
      Throws:
      IOException - the io exception
    • toBufferedImages

      public final List<BufferedImage> toBufferedImages(ToImageOptions options) throws IOException
      Rasterizes (renders) the PDF into BufferedImage objects. 1 BufferedImage for each page.
      Parameters:
      options - The ToImageOptions
      Returns:
      An array of BufferedImage objects.
      Throws:
      IOException - the io exception
    • toBufferedImages

      public final List<BufferedImage> toBufferedImages(PageSelection pageSelection) throws IOException
      Rasterizes (renders) the PDF into BufferedImage objects. 1 BufferedImage for each page.
      Parameters:
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      An array of BufferedImage objects.
      Throws:
      IOException - the io exception
    • toBufferedImages

      public final List<BufferedImage> toBufferedImages(ToImageOptions options, PageSelection pageSelection) throws IOException
      Rasterizes (renders) the PDF into BufferedImage objects. 1 BufferedImage for each page.
      Parameters:
      options - The ToImageOptions
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      An array of BufferedImage objects.
      Throws:
      IOException - the io exception
    • toPngImages

      public final List<String> toPngImages(String fileNamePattern) throws IOException
      Renders the pages of the PDF as PNG (Portable Network Graphic) files and saves them to disk.

      Specific image dimensions and page numbers may be given as optional parameters.

      fileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers.

      Parameters:
      fileNamePattern - A full or partial file path for the output files containing an asterisk. E.g. C:\images\pdf_pages_*.png
      Returns:
      An array of the file paths of the image files created.
      Throws:
      IOException - the io exception
    • toPngImages

      public final List<String> toPngImages(String fileNamePattern, ToImageOptions options) throws IOException
      Renders the pages of the PDF as PNG (Portable Network Graphic) files and saves them to disk.

      Specific image dimensions and page numbers may be given as optional parameters.

      fileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers.

      Parameters:
      fileNamePattern - A full or partial file path for the output files containing an asterisk. E.g. C:\images\pdf_pages_*.png
      options - The ToImageOptions
      Returns:
      An array of the file paths of the image files created.
      Throws:
      IOException - the io exception
    • toPngImages

      public final List<String> toPngImages(String fileNamePattern, PageSelection pageSelection) throws IOException
      Renders the pages of the PDF as PNG (Portable Network Graphic) files and saves them to disk.

      Specific image dimensions and page numbers may be given as optional parameters.

      fileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers.

      Parameters:
      fileNamePattern - A full or partial file path for the output files containing an asterisk. E.g. C:\images\pdf_pages_*.png
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      An array of the file paths of the image files created.
      Throws:
      IOException - the io exception
    • toPngImages

      public final List<String> toPngImages(String fileNamePattern, ToImageOptions options, PageSelection pageSelection) throws IOException
      Renders the pages of the PDF as PNG (Portable Network Graphic) files and saves them to disk.

      Specific image dimensions and page numbers may be given as optional parameters.

      fileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers.

      Parameters:
      fileNamePattern - A full or partial file path for the output files containing an asterisk. E.g. C:\images\pdf_pages_*.png
      options - The ToImageOptions
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      An array of the file paths of the image files created.
      Throws:
      IOException - the io exception
    • toImages

      public List<String> toImages(String fileNamePattern, String imageFileType) throws IOException
      Renders the pages of the PDF as specific image files type and saves them to disk.

      Specific image dimensions and page numbers may be given as optional parameters.

      fileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers.

      Parameters:
      fileNamePattern - A full or partial file path for the output files containing an asterisk. E.g. C:\images\pdf_page_*.jpg
      imageFileType - a specific image file type without dot. E.g. "jpg", "png", "bmp", "gif", "tiff"
      Returns:
      An array of the file paths of the image files created.
      Throws:
      IOException - the io exception
    • toImages

      public List<String> toImages(String fileNamePattern, String imageFileType, ToImageOptions options) throws IOException
      Renders the pages of the PDF as specific image files type and saves them to disk.

      Specific image dimensions and page numbers may be given as optional parameters.

      fileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers.

      Parameters:
      fileNamePattern - A full or partial file path for the output files containing an asterisk. E.g. C:\images\pdf_page_*.jpg
      imageFileType - a specific image file type without dot. E.g. "jpg", "png", "bmp", "gif", "tiff"
      options - The ToImageOptions
      Returns:
      An array of the file paths of the image files created.
      Throws:
      IOException - the io exception
    • toImages

      public List<String> toImages(String fileNamePattern, String imageFileType, PageSelection pageSelection) throws IOException
      Renders the pages of the PDF as specific image files type and saves them to disk.

      Specific image dimensions and page numbers may be given as optional parameters.

      fileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers.

      Parameters:
      fileNamePattern - A full or partial file path for the output files containing an asterisk. E.g. C:\images\pdf_page_*.jpg
      imageFileType - a specific image file type without dot. E.g. "jpg", "png", "bmp", "gif", "tiff"
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      An array of the file paths of the image files created.
      Throws:
      IOException - the io exception
    • toImages

      public List<String> toImages(String fileNamePattern, String imageFileType, ToImageOptions options, PageSelection pageSelection) throws IOException
      Renders the pages of the PDF as specific image files type and saves them to disk.

      Specific image dimensions and page numbers may be given as optional parameters.

      fileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers.

      Parameters:
      fileNamePattern - A full or partial file path for the output files containing an asterisk. E.g. C:\images\pdf_page_*.jpg
      imageFileType - a specific image file type without dot. E.g. "jpg", "png", "bmp", "gif", "tiff"
      options - The ToImageOptions
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      An array of the file paths of the image files created.
      Throws:
      IOException - the io exception
    • toJpegImages

      public final List<String> toJpegImages(String fileNamePattern) throws IOException
      Renders the pages of the PDF as JPEG image files and saves them to disk.

      Specific image dimensions and page numbers may be given as optional parameters.

      fileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers.

      Parameters:
      fileNamePattern - A full or partial file path for the output files containing an asterisk. E.g. C:\images\pdf_page_*.jpg
      Returns:
      An array of the file paths of the image files created.
      Throws:
      IOException - the io exception
    • toJpegImages

      public final List<String> toJpegImages(String fileNamePattern, ToImageOptions options) throws IOException
      Renders the pages of the PDF as JPEG image files and saves them to disk.

      Specific image dimensions and page numbers may be given as optional parameters.

      fileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers.

      Parameters:
      fileNamePattern - A full or partial file path for the output files containing an asterisk. E.g. C:\images\pdf_page_*.jpg
      options - The ToImageOptions
      Returns:
      An array of the file paths of the image files created.
      Throws:
      IOException - the io exception
    • toJpegImages

      public final List<String> toJpegImages(String fileNamePattern, PageSelection pageSelection) throws IOException
      Renders the pages of the PDF as JPEG image files and saves them to disk.

      Specific image dimensions and page numbers may be given as optional parameters.

      fileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers.

      Parameters:
      fileNamePattern - A full or partial file path for the output files containing an asterisk. E.g. C:\images\pdf_page_*.jpg
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      An array of the file paths of the image files created.
      Throws:
      IOException - the io exception
    • toJpegImages

      public final List<String> toJpegImages(String fileNamePattern, ToImageOptions options, PageSelection pageSelection) throws IOException
      Renders the pages of the PDF as JPEG image files and saves them to disk.

      Specific image dimensions and page numbers may be given as optional parameters.

      fileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers.

      Parameters:
      fileNamePattern - A full or partial file path for the output files containing an asterisk. E.g. C:\images\pdf_page_*.jpg
      options - The ToImageOptions
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      An array of the file paths of the image files created.
      Throws:
      IOException - the io exception
    • toMultiPageTiff

      public String toMultiPageTiff(Path filePath) throws IOException
      Renders the pages of the PDF as TIFF (Tagged Image File Format / Tif) file and saves it to disk. Specific image dimensions and page numbers may be given as optional parameters FileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers
      Parameters:
      filePath - A file path for the output file. E.g. C:\images\pdf_pages.tiff
      Returns:
      A file path of the image file created.
      Throws:
      IOException - the io exception
    • toMultiPageTiff

      public String toMultiPageTiff(Path filePath, PageSelection pageSelection) throws IOException
      Renders the pages of the PDF as TIFF (Tagged Image File Format / Tif) file and saves it to disk. Specific image dimensions and page numbers may be given as optional parameters FileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers
      Parameters:
      filePath - A file path for the output file. E.g. C:\images\pdf_pages.tiff
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      A file path of the image file created.
      Throws:
      IOException - the io exception
    • toMultiPageTiff

      public String toMultiPageTiff(Path filePath, ToImageOptions options) throws IOException
      Renders the pages of the PDF as TIFF (Tagged Image File Format / Tif) file and saves it to disk. Specific image dimensions and page numbers may be given as optional parameters FileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers
      Parameters:
      filePath - A file path for the output file. E.g. C:\images\pdf_pages.tiff
      options - The ToImageOptions
      Returns:
      A file path of the image file created.
      Throws:
      IOException - the io exception
    • toMultiPageTiff

      public String toMultiPageTiff(Path filePath, ToImageOptions options, PageSelection pageSelection) throws IOException
      Renders the pages of the PDF as TIFF (Tagged Image File Format / Tif) file and saves it to disk. Specific image dimensions and page numbers may be given as optional parameters FileNamePattern should normally contain an asterisk (*) character which will be substituted for the page numbers
      Parameters:
      filePath - A file path for the output file. E.g. C:\images\pdf_pages.tiff
      options - The ToImageOptions
      pageSelection - Selected page indexes. Default is all pages.
      Returns:
      A file path of the image file created.
      Throws:
      IOException - the io exception
    • compressImages

      public final void compressImages(int quality)
      Reduces the PDF's file size by compressing existing images using JPEG encoding and the specified quality setting.
      Parameters:
      quality - Quality (1 - 100) to use during compression
    • compressImages

      public final void compressImages(int quality, boolean scaleToVisibleSize)
      Reduces the PDF's file size by compressing existing images using JPEG encoding and the specified quality settings.
      Parameters:
      quality - Quality (1 - 100) to use during compression
      scaleToVisibleSize - Scale down the image resolution according to its visible size in the PDF document; may cause distortion with some image configurations. Default is false.
    • extractAllImages

      public final List<BufferedImage> extractAllImages() throws IOException
      Finds all embedded Images from within the PDF and returns them as a list of BufferedImage images.
      Returns:
      The extracted images as BufferedImage objects.
      Throws:
      IOException - the io exception
    • extractAllRawImages

      public final List<byte[]> extractAllRawImages() throws IOException
      Finds all embedded Images from within the PDF and returns as a list of image bytes
      Returns:
      The extracted images as byte arrays.
      Throws:
      IOException - the io exception
    • extractAllImagesFromPages

      public final List<BufferedImage> extractAllImagesFromPages(PageSelection pageSelection) throws IOException
      Finds all embedded Images from within the PDF and returns as a list of image bytes
      Parameters:
      pageSelection - The selected page index(es). Default is all pages.
      Returns:
      The extracted images as BufferedImage objects.
      Throws:
      IOException - the io exception
    • extractAllRawImagesFromPages

      public final List<byte[]> extractAllRawImagesFromPages(PageSelection pageSelection) throws IOException
      Finds all embedded Images from within the PDF and returns them as raw bytes.
      Parameters:
      pageSelection - The selected page index(es). Default is all pages.
      Returns:
      The extracted images as byte arrays.
      Throws:
      IOException - the io exception
    • saveAs

      public final PdfDocument saveAs(Path filePath) throws IOException
      Saves this PdfDocument to a file.
      Parameters:
      filePath - File Path
      Returns:
      This PdfDocument for fluid code notation.
      Throws:
      IOException - the io exception
    • saveAs

      public final PdfDocument saveAs(String filePath) throws IOException
      Saves this PdfDocument to a file.
      Parameters:
      filePath - File path string
      Returns:
      This PdfDocument for fluid code notation.
      Throws:
      IOException - the io exception
    • saveAsRevision

      public final PdfDocument saveAsRevision(Path filePath) throws IOException
      Saves this PdfDocument to a file.
      Parameters:
      filePath - File Path
      Returns:
      This PdfDocument for fluid code notation.
      Throws:
      IOException - the io exception
    • saveAsRevision

      public final PdfDocument saveAsRevision(String filePath) throws IOException
      Saves this PdfDocument to a file.
      Parameters:
      filePath - File path string
      Returns:
      This PdfDocument for fluid code notation.
      Throws:
      IOException - the io exception
    • getBinaryData

      public final byte[] getBinaryData()
      Saves the PDF as byte array, including any changes.
      Returns:
      The PDF file as a byte array.
    • getBinaryDataIncremental

      public final byte[] getBinaryDataIncremental()
      Saves the PDF as byte array with changes appended to the end of the file.
      Returns:
      The PDF file as a byte array.
    • getRevision

      public final PdfDocument getRevision(int index)
      Creates a copy of this document at the specified revision number. saveAsRevision(java.nio.file.Path)
      Parameters:
      index - revision index
      Returns:
      a PdfDocument document
    • print

      public void print() throws PrinterException
      Prints this PDF by sending it to the computer's real world printer(s).

      For advanced real-world printing options please implement your own java.awt.print code.

      This class PdfDocumentimplements java.awt.print.Printable.

      Throws:
      PrinterException - the printer exception
    • printWithoutDialog

      public void printWithoutDialog() throws PrinterException
      Prints this PDF by sending it to the computer's real world printer(s).

      For advanced real-world printing options please implement your own java.awt.print code.

      This class PdfDocumentimplements java.awt.print.Printable.

      Throws:
      PrinterException - the printer exception
    • print

      public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
      Specified by:
      print in interface Printable
      Throws:
      PrinterException
    • applyWatermark

      public final PdfDocument applyWatermark(String html, int opacity, VerticalAlignment verticalAlignment)
      Adds a watermark to this PDF.

      Please use applyStamp(Stamper) for more control.

      Parameters:
      html - The HTML fragment which will be stamped onto your PDF.
      opacity - Watermark transparent value. 0 is invisible, 100 if fully opaque.
      verticalAlignment - The vertical alignment of the watermark relative to the page.
      Returns:
      Returns this PdfDocument, allowing for a 'fluent' chained in-line code style
    • applyWatermark

      public final PdfDocument applyWatermark(String html, int opacity, VerticalAlignment verticalAlignment, HorizontalAlignment horizontalAlignment)
      Adds a watermark to this PDF.

      Please use applyStamp(Stamper) for more control.

      Parameters:
      html - The HTML fragment which will be stamped onto your PDF.
      opacity - Watermark transparent value. 0 is invisible, 100 if fully opaque.
      verticalAlignment - The vertical alignment of the watermark relative to the page.
      horizontalAlignment - The horizontal alignment of the watermark relative to the page.
      Returns:
      Returns this PdfDocument, allowing for a 'fluent' chained in-line code style
    • applyWatermark

      public final PdfDocument applyWatermark(String html, int opacity)
      Adds Watermark to PDF, Please use applyStamp(Stamper) for more control.
      Parameters:
      html - The HTML fragment which will be stamped onto your PDF.
      opacity - Watermark transparent value. 0 is invisible, 100 if fully opaque.
      Returns:
      Returns this PdfDocument, allowing for a 'fluent' chained in-line code style
    • applyWatermark

      public final PdfDocument applyWatermark(String html)
      Adds Watermark to PDF, Please use applyStamp(Stamper) for more control.
      Parameters:
      html - The HTML fragment which will be stamped onto your PDF.
      Returns:
      Returns this PdfDocument, allowing for a 'fluent' chained in-line code style
    • applyStamp

      public final PdfDocument applyStamp(Stamper stamper)
      Edits the PDF by applying the Stamper's rendered to every page.
      Parameters:
      stamper - The Stamper object that has the content to be stamped onto the PDF.
      Returns:
      Returns this PdfDocument, allowing for a 'fluent' chained in-line code style
    • applyStamp

      public final PdfDocument applyStamp(Stamper stamper, PageSelection pageSelection)
      Edits the PDF by applying the Stamper's rendered to only selected page(s).
      Parameters:
      stamper - The Stamper object that has the content to be stamped onto the PDF.
      pageSelection - The selected page index(es). Default is all pages,
      Returns:
      Returns this PdfDocument, allowing for a 'fluent' chained in-line code style
    • extractAllText

      public final String extractAllText()
      Extracts the written text content from the PDF and returns it as a string.
      Returns:
      All text in the PDF as a string.

      Pages are separated by 4 consecutive line breaks

    • extractTextFromPage

      public final String extractTextFromPage(PageSelection pageSelection)
      Extracts the text content from one page of the PDF and returns it as a string.
      Parameters:
      pageSelection - The selected page index(es). Default is all pages.
      Returns:
      The text extracted from the PDF page as a string.
    • replaceText

      public final void replaceText(PageSelection pageSelection, String oldText, String newText)
      Replace the specified old text with new text on a given page.
      Parameters:
      pageSelection - The selected page index(es).
      oldText - Old text to remove
      newText - New text to add
    • renderHtmlFileAsPdf

      public static PdfDocument renderHtmlFileAsPdf(String htmlFilePath) throws IOException
      Creates a PDF file from a local Html file, and returns it as a PdfDocument.
      Parameters:
      htmlFilePath - Path to a Html to be rendered as a PDF.
      Returns:
      A PdfDocument
      Throws:
      IOException - the io exception
    • renderHtmlFileAsPdf

      public static PdfDocument renderHtmlFileAsPdf(String htmlFilePath, String baseUrl) throws IOException
      Creates a PDF file from a local Html file, and returns it as a PdfDocument.
      Parameters:
      htmlFilePath - Path to a Html to be rendered as a PDF.
      baseUrl - Optional. Setting the BaseURL property gives the relative file path or URL context for hyperlinks, images, CSS and JavaScript files.
      Returns:
      A PdfDocument
      Throws:
      IOException - the io exception
    • renderHtmlFileAsPdf

      public static PdfDocument renderHtmlFileAsPdf(String htmlFilePath, ChromePdfRenderOptions renderOptions, ChromeHttpLoginCredentials loginCredentials) throws IOException
      Creates a PDF file from a local Html file, and returns it as a PdfDocument.
      Parameters:
      htmlFilePath - Path to a Html to be rendered as a PDF.
      renderOptions - Rendering options
      loginCredentials - Http login credentials
      Returns:
      A PdfDocument
      Throws:
      IOException - the io exception
    • renderHtmlFileAsPdf

      public static PdfDocument renderHtmlFileAsPdf(String htmlFilePath, String baseUrl, ChromePdfRenderOptions renderOptions, ChromeHttpLoginCredentials loginCredentials) throws IOException
      Creates a PDF file from a local Html file, and returns it as a PdfDocument.
      Parameters:
      htmlFilePath - Path to a Html to be rendered as a PDF.
      baseUrl - Optional. Setting the BaseURL property gives the relative file path or URL context for hyperlinks, images, CSS and JavaScript files.
      renderOptions - Rendering options
      loginCredentials - Http login credentials
      Returns:
      A PdfDocument
      Throws:
      IOException - the io exception
    • renderHtmlFileAsPdf

      public static PdfDocument renderHtmlFileAsPdf(String htmlFilePath, ChromeHttpLoginCredentials loginCredentials) throws IOException
      Creates a PDF file from a local Html file, and returns it as a PdfDocument.
      Parameters:
      htmlFilePath - Path to a Html to be rendered as a PDF.
      loginCredentials - Http login credentials
      Returns:
      A PdfDocument
      Throws:
      IOException - the io exception
    • renderHtmlFileAsPdf

      public static PdfDocument renderHtmlFileAsPdf(String htmlFilePath, String baseUrl, ChromeHttpLoginCredentials loginCredentials) throws IOException
      Creates a PDF file from a local Html file, and returns it as a PdfDocument.
      Parameters:
      htmlFilePath - Path to a Html to be rendered as a PDF.
      baseUrl - Optional. Setting the BaseURL property gives the relative file path or URL context for hyperlinks, images, CSS and JavaScript files.
      loginCredentials - Http login credentials
      Returns:
      A PdfDocument
      Throws:
      IOException - the io exception
    • renderHtmlFileAsPdf

      public static PdfDocument renderHtmlFileAsPdf(String htmlFilePath, ChromePdfRenderOptions renderOptions) throws IOException
      Creates a PDF file from a local Html file, and returns it as a PdfDocument.
      Parameters:
      htmlFilePath - Path to a Html to be rendered as a PDF.
      renderOptions - Rendering options
      Returns:
      A PdfDocument
      Throws:
      IOException - the io exception
    • renderHtmlFileAsPdf

      public static PdfDocument renderHtmlFileAsPdf(String htmlFilePath, String baseUrl, ChromePdfRenderOptions renderOptions) throws IOException
      Creates a PDF file from a local Html file, and returns it as a PdfDocument.
      Parameters:
      htmlFilePath - Path to a Html to be rendered as a PDF.
      baseUrl - Optional. Setting the BaseURL property gives the relative file path or URL context for hyperlinks, images, CSS and JavaScript files.
      renderOptions - Rendering options
      Returns:
      A PdfDocument
      Throws:
      IOException - the io exception
    • renderUrlAsPdf

      public static PdfDocument renderUrlAsPdf(String url)
      Creates a PDF file from a URL or local file path and returns it as a PdfDocument.
      Parameters:
      url - An absolute (fully formed) Uri. Points to the Html document to be rendered as a PDF.
      Returns:
      A PdfDocument
    • renderUrlAsPdf

      public static PdfDocument renderUrlAsPdf(String url, ChromePdfRenderOptions renderOptions, ChromeHttpLoginCredentials loginCredentials)
      Creates a PDF file from a URL or local file path and returns it as a PdfDocument.
      Parameters:
      url - An absolute (fully formed) Uri. Points to the Html document to be rendered as a PDF.
      renderOptions - Rendering options
      loginCredentials - Http login credentials
      Returns:
      A PdfDocument
    • renderUrlAsPdf

      public static PdfDocument renderUrlAsPdf(String url, ChromeHttpLoginCredentials loginCredentials)
      Creates a PDF file from a URL or local file path and returns it as a PdfDocument.
      Parameters:
      url - An absolute (fully formed) Uri. Points to the Html document to be rendered as a PDF.
      loginCredentials - Http login credentials
      Returns:
      A PdfDocument
    • renderUrlAsPdf

      public static PdfDocument renderUrlAsPdf(String url, ChromePdfRenderOptions renderOptions)
      Creates a PDF file from a URL or local file path and returns it as a PdfDocument.
      Parameters:
      url - An absolute (fully formed) Uri. Points to the Html document to be rendered as a PDF.
      renderOptions - Rendering options
      Returns:
      A PdfDocument
    • renderHtmlAsPdf

      public static PdfDocument renderHtmlAsPdf(String html, ChromePdfRenderOptions renderOptions, ChromeHttpLoginCredentials loginCredentials, String baseUrl)
      Creates a PDF file from a Html string, and returns it as a PdfDocument.
      Parameters:
      html - The Html to be rendered as a PDF.
      renderOptions - Rendering options
      loginCredentials - Http login credentials
      baseUrl - Optional. Setting the BaseURL property gives the relative file path or URL context for hyperlinks, images, CSS and JavaScript files.
      Returns:
      A PdfDocument
    • renderHtmlAsPdf

      public static PdfDocument renderHtmlAsPdf(String html)
      Creates a PDF file from a Html string, and returns it as a PdfDocument.
      Parameters:
      html - The Html to be rendered as a PDF.
      Returns:
      A PdfDocument
    • renderHtmlAsPdf

      public static PdfDocument renderHtmlAsPdf(String html, String baseUrl, ChromeHttpLoginCredentials loginCredentials)
      Creates a PDF file from a Html string, and returns it as a PdfDocument.
      Parameters:
      html - The Html to be rendered as a PDF.
      baseUrl - Optional. Setting the BaseURL property gives the relative file path or URL context for hyperlinks, images, CSS and JavaScript files.
      loginCredentials - Http login credentials
      Returns:
      A PdfDocument
    • renderHtmlAsPdf

      public static PdfDocument renderHtmlAsPdf(String html, String baseUrl, ChromePdfRenderOptions renderOptions)
      Creates a PDF file from a Html string, and returns it as a PdfDocument.
      Parameters:
      html - The Html to be rendered as a PDF.
      baseUrl - Optional. Setting the BaseURL property gives the relative file path or URL context for hyperlinks, images, CSS and JavaScript files.
      renderOptions - Rendering options
      Returns:
      A PdfDocument
    • renderHtmlAsPdf

      public static PdfDocument renderHtmlAsPdf(String html, ChromePdfRenderOptions renderOptions, ChromeHttpLoginCredentials loginCredentials)
      Creates a PDF file from a Html string, and returns it as a PdfDocument.
      Parameters:
      html - The Html to be rendered as a PDF.
      renderOptions - Rendering options
      loginCredentials - Http login credentials
      Returns:
      A PdfDocument
    • renderHtmlAsPdf

      public static PdfDocument renderHtmlAsPdf(String html, String baseUrl)
      Creates a PDF file from a Html string, and returns it as a PdfDocument.
      Parameters:
      html - The Html to be rendered as a PDF.
      baseUrl - Optional. Setting the BaseURL property gives the relative file path or URL context for hyperlinks, images, CSS and JavaScript files.
      Returns:
      A PdfDocument
    • renderHtmlAsPdf

      public static PdfDocument renderHtmlAsPdf(String html, ChromeHttpLoginCredentials loginCredentials)
      Creates a PDF file from a Html string, and returns it as a PdfDocument.
      Parameters:
      html - The Html to be rendered as a PDF.
      loginCredentials - Http login credentials
      Returns:
      A PdfDocument
    • renderHtmlAsPdf

      public static PdfDocument renderHtmlAsPdf(String html, ChromePdfRenderOptions renderOptions)
      Creates a PDF file from a Html string, and returns it as a PdfDocument.
      Parameters:
      html - The Html to be rendered as a PDF.
      renderOptions - Rendering options
      Returns:
      A PdfDocument
    • renderRtfAsPdf

      public static PdfDocument renderRtfAsPdf(String rtfString)
      Creates a PDF file from RTF string, and returns it as a PdfDocument.
      Parameters:
      rtfString - The RTF string to be rendered as a PDF.
      Returns:
      A PdfDocument
    • renderRtfFileAsPdf

      public static PdfDocument renderRtfFileAsPdf(String rtfFilePath) throws IOException
      Creates a PDF file from RTF file, and returns it as a PdfDocument.
      Parameters:
      rtfFilePath - The RTF file path to be rendered as a PDF.
      Returns:
      A PdfDocument
      Throws:
      IOException - the io exception
    • renderRtfFileAsPdf

      public static PdfDocument renderRtfFileAsPdf(Path rtfFilePath) throws IOException
      Creates a PDF file from RTF file, and returns it as a PdfDocument.
      Parameters:
      rtfFilePath - The RTF file path to be rendered as a PDF.
      Returns:
      A PdfDocument
      Throws:
      IOException - the io exception
    • renderZipAsPdf

      public static PdfDocument renderZipAsPdf(Path zipFilePath, String mainFile, ChromePdfRenderOptions renderOptions) throws IOException
      Creates a PDF file from a local Zip file, and returns it as a PdfDocument.

      IronPDF is a W3C standards compliant HTML rendering based on Google's Chromium browser. If your output PDF does not look as expected:

      - Validate your HTML file using https://validator.w3.org/ & CSS https://jigsaw.w3.org/css-validator/

      - To debug HTML, view the file in Chrome web browser's print preview which will work almost exactly as IronPDF.

      - Read our detailed documentation on pixel perfect HTML to PDF: https://ironpdf.com/tutorials/pixel-perfect-html-to-pdf/

      Parameters:
      zipFilePath - Path to a Zip to be rendered as a PDF.
      mainFile - Name of the primary HTML file.
      renderOptions - Rendering options
      Returns:
      A PdfDocument
      Throws:
      IOException - the io exception
    • renderZipAsPdf

      public static PdfDocument renderZipAsPdf(Path zipFilePath, String mainFile) throws IOException
      Creates a PDF file from a local Zip file, and returns it as a PdfDocument.

      IronPDF is a W3C standards compliant HTML rendering based on Google's Chromium browser. If your output PDF does not look as expected:

      - Validate your HTML file using https://validator.w3.org/ & CSS https://jigsaw.w3.org/css-validator/

      - To debug HTML, view the file in Chrome web browser's print preview which will work almost exactly as IronPDF.

      - Read our detailed documentation on pixel perfect HTML to PDF: https://ironpdf.com/tutorials/pixel-perfect-html-to-pdf/

      Parameters:
      zipFilePath - Path to a Zip to be rendered as a PDF.
      mainFile - Name of the primary HTML file.
      Returns:
      A PdfDocument
      Throws:
      IOException - the io exception