com.aspose.pdf

Interfaces

Classes

Enums

Exceptions

com.aspose.pdf

Class Document

  • All Implemented Interfaces:
    com.aspose.ms.System.IDisposable, IDocument


    public final class Document
    extends Object
    implements IDocument

    Class representing PDF document

    • Field Detail

      • AbsentFontHandler

        public com.aspose.pdf.ADocument.AbsentFontHandler AbsentFontHandler
        Notification about missing fonts while processing documents.
      • FontSubstitution

        public final PdfEvent<com.aspose.pdf.ADocument.FontSubstitutionHandler> FontSubstitution

        It occurs when font replaces another font in document.

    • Constructor Detail

      • Document

        public Document()

        Initializes empty document.

      • Document

        public Document(InputStream input)

        Initialize new Document instance from the input stream.

        Parameters:
        input - Stream with pdf document.
      • Document

        public Document(InputStream input,
                        String password)

        Initialize new Document instance from the input stream.

        Parameters:
        input - Input stream object, corresponding pdf is password protected.
        password - User or owner password.
      • Document

        public Document(com.aspose.ms.System.IO.Stream input)

        Initialize new Document instance from the input stream.

        Parameters:
        input - Stream with pdf document.
      • Document

        public Document(InputStream input,
                        String password,
                        boolean isManagedStream)

        Initialize new Document instance from the input stream.

        Parameters:
        input - Stream with pdf document.
        password - User or owner password.
        isManagedStream - if set to true inner stream is closed before exit; otherwise, is not.
      • Document

        public Document(InputStream input,
                        boolean isManagedStream)

        Initialize new Document instance from the input stream.

        Parameters:
        input - Stream with pdf document.
        isManagedStream - if set to true inner stream is closed before exit; otherwise, is not.
      • Document

        public Document(InputStream input,
                        LoadOptions options)

        Opens an existing document from a stream providing necessary converting to get pdf document.

        Parameters:
        input - Input stream to convert into pdf document.
        options - Represents properties for converting input into pdf document.
      • Document

        public Document(String filename,
                        LoadOptions options)

        Opens an existing document from a file providing necessary converting to get pdf document.

        Parameters:
        filename - Input file to convert into pdf document.
        options - Represents properties for converting filename into pdf document.
      • Document

        public Document(com.aspose.ms.System.IO.Stream input,
                        String password)

        Opens an existing document from a stream.

        Parameters:
        input - Input file to convert into pdf document.
        password - User or owner password.
      • Document

        public Document(String filename)

        Just init Document using filename. The same as Document(Stream).

        Parameters:
        filename - The name of the pdf document file.
      • Document

        public Document(String filename,
                        String password)

        Initializes new instance of the Document class for working with encrypted document.

        Parameters:
        filename - Document file name.
        password - User or owner password.
      • Document

        public Document(String filename,
                        String password,
                        boolean isManagedStream)

        Initializes new instance of the Document class for working with encrypted document.

        Parameters:
        filename - Document file name.
        password - User or owner password.
        isManagedStream - if set to true inner stream is closed before exit; otherwise, is not.
    • Method Detail

      • getPageInfo

        public PageInfo getPageInfo()

        Gets the page info.(for generator only)

        Specified by:
        getPageInfo in interface IDocument
        Returns:
        The page info.
      • setPageInfo

        public void setPageInfo(PageInfo value)

        Sets the page info.(for generator only)

        Specified by:
        setPageInfo in interface IDocument
        Parameters:
        value - PageInfo object
      • getPdfFormat

        public int getPdfFormat()

        Gets pdfa format

        Specified by:
        getPdfFormat in interface IDocument
        Returns:
        PdfFormat element
        See Also:
        PdfFormat
      • removePdfaCompliance

        public void removePdfaCompliance()

        Remove pdfa compliance from the document

        Specified by:
        removePdfaCompliance in interface IDocument
      • getCollection

        public Collection getCollection()

        Gets collection of document.

        Specified by:
        getCollection in interface IDocument
        Returns:
        Collection object
      • setCollection

        public void setCollection(Collection value)

        Sets collection of document.

        Specified by:
        setCollection in interface IDocument
        Parameters:
        value - Collection object
      • getEngineDoc

        public com.aspose.pdf.engine.IPdfDocument getEngineDoc()

        Instance of IPdfDocument used to access to internal document structure. Internal only

        Specified by:
        getEngineDoc in interface IDocument
        Returns:
        IPdfDocument object
      • getVersion

        public String getVersion()

        Gets a version of Pdf from Pdf file header.

        Specified by:
        getVersion in interface IDocument
        Returns:
        String value
      • getOpenAction

        public IAppointment getOpenAction()

        Gets action performed at document opening.


         Example demonstrates how to get CenterWindow flag:
        
         Document document = new Document("sample.pdf");
         IAppointment value = document.getOpenAction();
         
        Specified by:
        getOpenAction in interface IDocument
        Returns:
        IAppointment object
      • setOpenAction

        public void setOpenAction(IAppointment value)

        Sets action performed at document opening.

        Specified by:
        setOpenAction in interface IDocument
        Parameters:
        value - IAppointment value
      • isHideToolBar

        public boolean isHideToolBar()

        Gets flag specifying whether toolbar should be hidden when document is active.

        Specified by:
        isHideToolBar in interface IDocument
        Returns:
        boolean value
         Example demonstrates how to get HideToolBar flag:
        
         Document document = new Document("sample.pdf");
         boolean value = document.isHideToolBar();
         
      • setHideToolBar

        public void setHideToolBar(boolean value)

        Set flag specifying whether toolbar should be hidden when document is active.

        Specified by:
        setHideToolBar in interface IDocument
        Parameters:
        value - boolean value
      • isHideMenubar

        public boolean isHideMenubar()

        Gets flag specifying whether menu bar should be hidden when document is active.

        Specified by:
        isHideMenubar in interface IDocument
        Returns:
        boolean value
         Example demonstrates how to get HideMenubar flag:
        
         Document document = new Document("sample.pdf");
         boolean value = document.isHideMenubar();
         
      • setHideMenubar

        public void setHideMenubar(boolean value)

        Sets flag specifying whether menu bar should be hidden when document is active.

        Specified by:
        setHideMenubar in interface IDocument
        Parameters:
        value - boolean value
      • isHideWindowUI

        public boolean isHideWindowUI()

        Gets flag specifying whether user interface elements should be hidden when document is active.

        Specified by:
        isHideWindowUI in interface IDocument
        Returns:
        boolean value
         Example demonstrates how to get HideWindowUI flag:
        
         Document document = new Document("sample.pdf");
         boolean value = document.isHideWindowUI();
         
      • setHideWindowUI

        public void setHideWindowUI(boolean value)

        Sets flag specifying whether user interface elements should be hidden when document is active.

        Specified by:
        setHideWindowUI in interface IDocument
        Parameters:
        value - boolean value
      • isFitWindow

        public boolean isFitWindow()

        Gets flag specifying whether document window must be resized to fit the first displayed page.

        Specified by:
        isFitWindow in interface IDocument
        Returns:
        boolean value
         Example demonstrates how to get FitWindow flag:
        
         Document document = new Document("sample.pdf");
         boolean value = document.isFitWindow();
         
      • setFitWindow

        public void setFitWindow(boolean value)

        Sets flag specifying whether document window must be resized to fit the first displayed page.

        Specified by:
        setFitWindow in interface IDocument
        Parameters:
        value - boolean value
      • isCenterWindow

        public boolean isCenterWindow()

        Gets flag specifying whether position of the document's window will be centered on the screen.

        Specified by:
        isCenterWindow in interface IDocument
        Returns:
        boolean value
         Example demonstrates how to get CenterWindow flag:
        
         Document document = new Document("sample.pdf");
         boolean value = document.isCenterWindow();
         
      • setCenterWindow

        public void setCenterWindow(boolean value)

        Sets flag specifying whether position of the document's window will be centered on the screen.

        Specified by:
        setCenterWindow in interface IDocument
        Parameters:
        value - boolean value
      • isDisplayDocTitle

        public boolean isDisplayDocTitle()

        Gets flag specifying whether document's window title bar should display document title.

        Specified by:
        isDisplayDocTitle in interface IDocument
        Returns:
        boolean value
         Example demonstrates how to get DisplayDocTitle flag:
        
         Document document = new Document("sample.pdf");
         boolean value = document.isDisplayDocTitle();
         
      • setDisplayDocTitle

        public void setDisplayDocTitle(boolean value)

        Sets flag specifying whether document's window title bar should display document title.

        Specified by:
        setDisplayDocTitle in interface IDocument
        Parameters:
        value - boolean value
      • getPages

        public PageCollection getPages()

        Gets collection of document pages. Note that pages are numbered from 1 in collection.

        Specified by:
        getPages in interface IDocument
        Returns:
        PageCollection object
         Example below demonstrates how to operate with the document pages:
         How to obtain number of pages and how to obtain rectangle of starting page of the document.
        
         Document document = new Document("sample.pdf");
         PageCollection  pages = document.getPages();
         System.out.println("Document contains " + pages.size());
         Page page = pages.get_Item(1);
         Rectangle rect = page.getRect();
         
      • getActions

        public DocumentActionCollection getActions()

        Gets document actions. This property is instance of DocumentActions class which allows to get/set BeforClosing, BeforSaving, etc. actions.

        Specified by:
        getActions in interface IDocument
        Returns:
        DocumentActionCollection object
         This example demonstrates how to obtain after open action of the document:
        
         Document document = new Document("PdfWithOpenAction.pdf");
         DocumentActionCollection actions = document.getActions();
         PdfAction afterSavingAction = actions.getAfterSaving();
         
      • getForm

        public Form getForm()

        Gets Acro Form of the document.

        Specified by:
        getForm in interface IDocument
        Returns:
        Form object
      • getDirection

        public int getDirection()

        Gets reading order of text: L2R (left to right) or R2L (right to left).

        Specified by:
        getDirection in interface IDocument
        Returns:
        Direction element
        See Also:
        Direction
      • setDirection

        public void setDirection(int value)

        Sets reading order of text: L2R (left to right) or R2L (right to left).

        Specified by:
        setDirection in interface IDocument
        Parameters:
        value - int value
        See Also:
        Direction
      • getPageMode

        public int getPageMode()

        Gets page mode, specifying how document should be displayed when opened.

        Specified by:
        getPageMode in interface IDocument
        Returns:
        PageMode element
        See Also:
        PageMode
      • setPageMode

        public void setPageMode(int pageMode)

        Sets page mode, specifying how document should be displayed when opened.

        Specified by:
        setPageMode in interface IDocument
        Parameters:
        pageMode - int value
        See Also:
        PageMode
      • getNonFullScreenPageMode

        public int getNonFullScreenPageMode()

        Gets page mode, specifying how to display the document on exiting full-screen mode.

        Specified by:
        getNonFullScreenPageMode in interface IDocument
        Returns:
        PageMode element
        See Also:
        PageMode
      • setNonFullScreenPageMode

        public void setNonFullScreenPageMode(int value)

        Sets page mode, specifying how to display the document on exiting full-screen mode.

        Specified by:
        setNonFullScreenPageMode in interface IDocument
        Parameters:
        value - int value
        See Also:
        PageMode
      • getPageLayout

        public int getPageLayout()

        Gets page layout which shall be used when the document is opened.

        Specified by:
        getPageLayout in interface IDocument
        Returns:
        PageLayout element
        See Also:
        PageLayout
      • setPageLayout

        public void setPageLayout(int value)

        Sets page layout which shall be used when the document is opened.

        Specified by:
        setPageLayout in interface IDocument
        Parameters:
        value - int value
        See Also:
        PageLayout
      • getFileName

        public String getFileName()

        Name of the PDF file that caused this document

        Specified by:
        getFileName in interface IDocument
        Returns:
        String object
      • getMetadata

        public Metadata getMetadata()

        Document metadata. (A PDF document may include general information, such as the document's title, author, and creation and modification dates. Such global information about the document (as opposed to its content or structure) is called metadata and is intended to assist in cataloguing and searching for documents in external databases.)

        Specified by:
        getMetadata in interface IDocument
        Returns:
        Metadata object
      • processParagraphs

        public void processParagraphs()

        Stores document into stream.

        Specified by:
        processParagraphs in interface IDocument
      • saveInternal

        public void saveInternal(com.aspose.ms.System.IO.Stream output)

        For internal usage only

        Parameters:
        output - For internal usage only
      • save

        public void save(OutputStream output)

        Stores document into stream.

        Specified by:
        save in interface IDocument
        Parameters:
        output - Stream where document shell be stored.
      • save

        public void save(String outputFileName)

        Saves document into the specified file.

        Specified by:
        save in interface IDocument
        Parameters:
        outputFileName - Path to file where the document will be stored.
      • exportAnnotationsToXfdf

        public void exportAnnotationsToXfdf(String fileName)

        Exports all document annotations to XFDF file

        Specified by:
        exportAnnotationsToXfdf in interface IDocument
        Parameters:
        fileName - XFDF file name
      • sendTo

        public void sendTo(DocumentDevice device,
                           OutputStream output)

        Sends the whole document to the document device for processing.

        Specified by:
        sendTo in interface IDocument
        Parameters:
        device - Document device which is used to process the document.
        output - Output stream contains the results of the document processing with given device.
      • sendTo

        public void sendTo(DocumentDevice device,
                           int fromPage,
                           int toPage,
                           OutputStream output)

        Sends the certain pages of the document to the document device for processing.

        Specified by:
        sendTo in interface IDocument
        Parameters:
        device - Document device which is used to process the document.
        fromPage - The first page for processing.
        toPage - The last page for processing.
        output - Output stream contains the results of the document pages processing with given device.
      • sendTo

        public void sendTo(DocumentDevice device,
                           String outputFileName)

        Sends the whole document to the document device for processing.

        Specified by:
        sendTo in interface IDocument
        Parameters:
        device - Document device which is used to process the document.
        outputFileName - Output file name with the results of processing.
      • sendTo

        public void sendTo(DocumentDevice device,
                           int fromPage,
                           int toPage,
                           String outputFileName)

        Sends the whole document to the document device for processing.

        Specified by:
        sendTo in interface IDocument
        Parameters:
        device - Document device which is used to process the document.
        fromPage - The first page for processing.
        toPage - The last page for processing.
        outputFileName - Output file name with the results of processing.
      • removeMetadata

        public void removeMetadata()

        Removes metadata from the document.

        Specified by:
        removeMetadata in interface IDocument
      • importAnnotationsFromXfdf

        public void importAnnotationsFromXfdf(String fileName)

        Imports annotations from XFDF file to document.

        Specified by:
        importAnnotationsFromXfdf in interface IDocument
        Parameters:
        fileName - XFDF file name
      • validate

        public boolean validate(String outputLogFileName,
                                int format)

        Validate document into the specified file.

        Specified by:
        validate in interface IDocument
        Parameters:
        outputLogFileName - Path to file where the comments will be stored.
        format - PdfFormat element.
        Returns:
        The operation result
        See Also:
        PdfFormat
      • convert

        public boolean convert(String outputLogFileName,
                               int format,
                               int action)

        Convert document and save errors into the specified file.

        Specified by:
        convert in interface IDocument
        Parameters:
        outputLogFileName - Path to file where the comments will be stored.
        format - Pdf format.
        action - Action for objects that can not be converted
        Returns:
        boolean value
        See Also:
        PdfFormat, ConvertErrorAction
      • validate

        public boolean validate(OutputStream outputLogStream,
                                int format)
        Validate document into the specified file.
        Specified by:
        validate in interface IDocument
        Parameters:
        outputLogStream - Stream where the comments will be stored.
        format - Pdf format.
        Returns:
        boolean value
        See Also:
        PdfFormat
      • convert

        public boolean convert(String outputLogFileName,
                               int format,
                               int action,
                               int transparencyAction)

        Convert document and save errors into the specified file.

        Specified by:
        convert in interface IDocument
        Parameters:
        outputLogFileName - Path to file where the comments will be stored.
        format - The pdf format.
        action - Action for objects that can not be converted
        transparencyAction - Action for image masked objects
        Returns:
        The operation result
        See Also:
        PdfFormat, ConvertErrorAction, ConvertTransparencyAction
      • convert

        public boolean convert(Document.CallBackGetHocr callback)
        Convert document and save errors into the specified file.
        Specified by:
        convert in interface IDocument
        Parameters:
        callback - Action for objects that can not be converted
        Returns:
        boolean value
      • convertInternal

        public boolean convertInternal(com.aspose.ms.System.IO.Stream outputLogStream,
                                       int format,
                                       int action)

        Convert document and save errors into the specified stream.

        Specified by:
        convertInternal in interface IDocument
        Parameters:
        outputLogStream - Stream where the comments will be stored.
        format - Pdf format.
        action - Action for objects that can not be converted
        Returns:
        boolean value
      • convert

        public boolean convert(OutputStream outputLogStream,
                               int format,
                               int action)

        Convert document and save errors into the specified stream.

        Specified by:
        convert in interface IDocument
        Parameters:
        outputLogStream - Stream where the comments will be stored.
        format - Pdf format.
        action - Action for objects that can not be converted
        Returns:
        boolean value
        See Also:
        PdfFormat, ConvertErrorAction
      • convert

        public boolean convert(PdfFormatConversionOptions options)

        Convert document using specified conversion options

        Specified by:
        convert in interface IDocument
        Parameters:
        options - set of options for convert PDF document
        Returns:
        The operation result
      • flatten

        public void flatten()

        Removes all fields from the document and place their values instead.

        Specified by:
        flatten in interface IDocument
      • getCryptoAlgorithm

        public int getCryptoAlgorithm()

        Gets security settings if document is encrypted. If document is not encrypted then corresponding exception will be raised in .net 1.1 or CryptoAlgorithm will be null for other .net versions.

        Specified by:
        getCryptoAlgorithm in interface IDocument
        Returns:
        CryptoAlgorithm element
        See Also:
        CryptoAlgorithm
      • encrypt

        public void encrypt(String userPassword,
                            String ownerPassword,
                            DocumentPrivilege privileges,
                            int cryptoAlgorithm,
                            boolean usePdf20)

        Encrypts the document. Call then Save to get encrypted version of the document.

        Specified by:
        encrypt in interface IDocument
        Parameters:
        userPassword - User password.
        ownerPassword - Owner password.
        privileges - Document permissions, see Permissions for details.
        cryptoAlgorithm - Cryptographic algorithm, see CryptoAlgorithm for details.
        usePdf20 - Support for revision 6 (Extension 8).
        See Also:
        CryptoAlgorithm
      • encrypt

        public void encrypt(String userPassword,
                            String ownerPassword,
                            int permissions,
                            int cryptoAlgorithm)

        Encrypts the document. Call then Save to get encrypted version of the document.

        Specified by:
        encrypt in interface IDocument
        Parameters:
        userPassword - User password.
        ownerPassword - Owner password.
        permissions - Document permissions, see Permissions for details.
        cryptoAlgorithm - Cryptographic algorithm, see CryptoAlgorithm for details.
        See Also:
        Permissions, CryptoAlgorithm
      • encrypt

        public void encrypt(String userPassword,
                            String ownerPassword,
                            int permissions,
                            int cryptoAlgorithm,
                            boolean usePdf20)

        Encrypts the document. Call then Save to get encrypted version of the document.

        Specified by:
        encrypt in interface IDocument
        Parameters:
        userPassword - User password.
        ownerPassword - Owner password.
        permissions - Document permissions, see Permissions for details.
        cryptoAlgorithm - Cryptographic algorithm, see CryptoAlgorithm for details.
        usePdf20 - Support for revision 6 (Extension 8).
        See Also:
        Permissions, CryptoAlgorithm
      • changePasswords

        public void changePasswords(String ownerPassword,
                                    String newUserPassword,
                                    String newOwnerPassword)

        Changes document passwords. This action can be done only using owner password.

        Specified by:
        changePasswords in interface IDocument
        Parameters:
        ownerPassword - Owner password.
        newUserPassword - New user password.
        newOwnerPassword - New owner password.
      • isLinearized

        public boolean isLinearized()

        Gets a value indicating whether document is linearized.

        Specified by:
        isLinearized in interface IDocument
        Returns:
        boolean value
      • setLinearized

        public void setLinearized(boolean value)

        Sets a value indicating whether document is linearized.

        Specified by:
        setLinearized in interface IDocument
        Parameters:
        value - boolean value
      • decrypt

        public void decrypt()

        Decrypts the document. Call then Save to obtain decrypted version of the document.

        Specified by:
        decrypt in interface IDocument
      • getPermissions

        public int getPermissions()

        Gets permissions of the document.

        Specified by:
        getPermissions in interface IDocument
        Returns:
        int value
      • isEncrypted

        public boolean isEncrypted()

        Gets encrypted status of the document. True if document is encrypted.

        Specified by:
        isEncrypted in interface IDocument
        Returns:
        boolean value
      • optimize

        public void optimize()

        Linearize document in order to - open the first page as quickly as possible; - display next page or follow by link to the next page as quickly as possible; - display the page incrementally as it arrives when data for a page is delivered over a slow channel (display the most useful data first); - permit user interaction, such as following a link, to be performed even before the entire page has been received and displayed. Invoking this method doesn't actually saves the document. On the contrary the document only is prepared to have optimized structure, call then Save to get optimized document.

        Specified by:
        optimize in interface IDocument
      • save

        public void save()

        Save document incrementally (i.e. using incremental update technique).


        In order to save document incrementally we should open the document file for writing. Therefore Document must not be initialized with InputStream but with path to the file, like in the next code snippet: Document doc = new Document("document.pdf"); // make some changes and save the document incrementally doc.save();

        In case when document was initialized with InputStream, writing to InputStream is impossible, so we recommend to use separate methods "save" to save document or "saveIncrementally" to save document incrementally.
        Specified by:
        save in interface IDocument
      • save

        public void save(String outputFileName,
                         int format)

        Saves the document with a new name along with a file format.

        Parameters:
        outputFileName - Path to file where the document will be stored.
        format - Format options.
        See Also:
        SaveFormat
      • saveIncrementally

        public void saveIncrementally(OutputStream output)
        Saves incrementally the PDF Document to the specified stream.
        Specified by:
        saveIncrementally in interface IDocument
        Parameters:
        output - OutputStream object
      • saveIncrementally

        public void saveIncrementally(String outputFileName)
        Saves incrementally the PDF Document to the specified stream.
        Specified by:
        saveIncrementally in interface IDocument
        Parameters:
        outputFileName - OutputStream object
      • save

        public void save(OutputStream outputStream,
                         int format)

        Saves the document with a new name along with a file format.

        Specified by:
        save in interface IDocument
        Parameters:
        outputStream - Stream where the document will be stored.
        format - Format options.
        Throws:
        com.aspose.ms.System.ArgumentException - ArgumentException when HtmlSaveOptions is passed to a method. Save a document to the html stream is not supported. Please use method save to the file.
        See Also:
        SaveFormat
      • save

        public void save(String outputFileName,
                         SaveOptions options)

        Saves the document with a new name setting its save options.

        Specified by:
        save in interface IDocument
        Parameters:
        outputFileName - Path to file where the document will be stored.
        options - Save options.
      • save

        public void save(OutputStream outputStream,
                         SaveOptions options)

        Saves the document to a stream with a save options.

        Specified by:
        save in interface IDocument
        Parameters:
        outputStream - Stream where the document will be stored.
        options - Save options.
        Throws:
        com.aspose.ms.System.ArgumentException - ArgumentException when HtmlSaveOptions is passed to a method. Save a document to the html stream is not supported. Please use method save to the file.
      • getId

        public Id getId()

        Gets the ID.

        Specified by:
        getId in interface IDocument
        Returns:
        Id object
      • getMetadataStream

        public com.aspose.pdf.engine.data.types.IPdfStreamAccessor getMetadataStream()

        Returns raw metadata stream

        Specified by:
        getMetadataStream in interface IDocument
        Returns:
        IPdfStreamAccessor object
      • suppressUpdate

        public void suppressUpdate()

        Suppresses update contents data for all pages The contents is not updated until ResumeUpdate is called

        Specified by:
        suppressUpdate in interface IDocument
      • resumeUpdate

        public void resumeUpdate()

        resumes document update

        Specified by:
        resumeUpdate in interface IDocument
      • dispose

        public void dispose()

        Closes all resources used by this document.

        Specified by:
        dispose in interface com.aspose.ms.System.IDisposable
        Specified by:
        dispose in interface IDocument
      • getBackground

        public Color getBackground()

        Gets the background color of the document.

        Specified by:
        getBackground in interface IDocument
        Returns:
        Color object
      • setBackground

        public void setBackground(Color value)

        Sets the background color of the document.

        Specified by:
        setBackground in interface IDocument
        Parameters:
        value - Color object
      • getDefaultCopier

        public Copier getDefaultCopier()

        Returns copier used for coping pages to this document.

        Specified by:
        getDefaultCopier in interface IDocument
        Returns:
        Copier object
      • optimizeResources

        public void optimizeResources()

        Optimize resources in the document: 1. Resources which are not used on the document pages are removed; 2. Equal resources are joined into one object; 3. Unused objects are deleted.

        Specified by:
        optimizeResources in interface IDocument
      • optimizeResources

        public void optimizeResources(Document.OptimizationOptions strategy)

        Optimize resources in the document according to defined optimization strategy.

        Parameters:
        strategy - Optimization strategy.
      • getOptimizeSize

        public boolean getOptimizeSize()

        Gets optimization flag. When pages are added to document, equal resource streams in resultant file are merged into one PDF object if this flag set. This allows to decrease resultant file size but may cause slower execution and larger memory requirements. Default value: false.

        Specified by:
        getOptimizeSize in interface IDocument
        Returns:
        boolean value
      • setOptimizeSize

        public void setOptimizeSize(boolean value)

        Sets optimization flag. When pages are added to document, equal resource streams in resultant file are merged into one PDF object if this flag set. This allows to decrease resultant file size but may cause slower execution and larger memory requirements. Default value: false.

        Specified by:
        setOptimizeSize in interface IDocument
        Parameters:
        value - boolean value
      • getIgnoreCorruptedObjects

        public boolean getIgnoreCorruptedObjects()

        Gets or sets flag of ignoring errors in source files. When pages from source document copied into destination document, copying process is stopped with exception if some objects in source files are corrupted when this flag is false. example: dest.Pages.Add(src.Pages); If this flag is set to true then corrupted objects will be replaced with empty values. By default: true.

        Specified by:
        getIgnoreCorruptedObjects in interface IDocument
        Returns:
        boolean value
      • setIgnoreCorruptedObjects

        public void setIgnoreCorruptedObjects(boolean value)

        Gets or sets flag of ignoring errors in source files. When pages from source document copied into destination document, copying process is stopped with exception if some objects in source files are corrupted when this flag is false. example: dest.Pages.Add(src.Pages); If this flag is set to true then corrupted objects will be replaced with empty values. By default: true.

        Specified by:
        setIgnoreCorruptedObjects in interface IDocument
        Parameters:
        value - boolean value
      • getCatalogValue

        public Object getCatalogValue(String key)

        Returns item value from catalog dictionary.

        Specified by:
        getCatalogValue in interface IDocument
        Parameters:
        key - The key of item.
        Returns:
        Item value - if key was successfully found; otherwise, null.
      • freeMemory

        public void freeMemory()

        Clears memory

        Specified by:
        freeMemory in interface IDocument
      • isAbsentFontTryToSubstitute

        public boolean isAbsentFontTryToSubstitute()
        Flag which informs about replacement of missing font.
        Specified by:
        isAbsentFontTryToSubstitute in interface IDocument
        Returns:
        boolean value
      • setAbsentFontTryToSubstitute

        public void setAbsentFontTryToSubstitute(boolean setAbsentFontTryToSubstitute)
        Setting flag for set program determined font in case of absense font.
        Specified by:
        setAbsentFontTryToSubstitute in interface IDocument
        Parameters:
        setAbsentFontTryToSubstitute - boolean value
      • check

        public boolean check(boolean doRepair)
        Validates document.
        Specified by:
        check in interface IDocument
        Parameters:
        doRepair - If true found issues will be repaired.
        Returns:
        boolean value
      • isManualDisposeEnabled

        public boolean isManualDisposeEnabled()
        By default method save close internal streams and release memory resources. We can do some operations and continue work with the document after method save if this ManualDispose parameter is enabled.
        Specified by:
        isManualDisposeEnabled in interface IDocument
        Returns:
        boolean value. (Default value == false)
      • setManualDisposeEnabled

        public void setManualDisposeEnabled(boolean manualDisposeEnabled)
        By default method save closes internal streams and release memory resources. We can do some operations and continue work with the document after method save is called if this ManualDispose parameter is enabled. But it is strongly recommended to call the dispose method when the Document instance is no longer needed.
        Specified by:
        setManualDisposeEnabled in interface IDocument
        Parameters:
        manualDisposeEnabled - boolean value. (Default value == false)
      • isSkippedPdfaCompliantValidationBeforeSave

        public boolean isSkippedPdfaCompliantValidationBeforeSave()
        By default pdfa validation process is necessary to update or remove pdfa compliant data if some rules were broken. But for fast saving process is can be skipped.
        Returns:
        boolean value
      • setSkipPdfaCompliantValidationBeforeSave

        public void setSkipPdfaCompliantValidationBeforeSave(boolean pdfaCompliantValidationBeforeSave)
        By default pdfa validation process is necessary to update or remove pdfa if some rules were broken. But for fast saving process is can be skipped.
        Parameters:
        pdfaCompliantValidationBeforeSave - boolean value
      • getJavaScript

        public JavaScriptCollection getJavaScript()

        Collection of JavaScript of document level.

        Returns:
        JavaScriptCollection object
      • isLicensed

        public static boolean isLicensed()

        Gets licensed state of the system. Returns true is system works in licensed mode and false otherwise.

        Returns:
        boolean value
      • setLayersAdded

        public void setLayersAdded(boolean value)
        Description copied from interface: IDocument
        Set LayersAdded value
        Specified by:
        setLayersAdded in interface IDocument
        Parameters:
        value - boolean value
      • startOperation

        public static void startOperation()
      • endOperation

        public static void endOperation()
      • isPdfaCompliant

        public boolean isPdfaCompliant()

        Gets the is document pdfa compliant.

        Specified by:
        isPdfaCompliant in interface IDocument
        Returns:
        boolean value
      • isPdfUaCompliant

        public boolean isPdfUaCompliant()

        Gets the is document pdfua compliant.

        Specified by:
        isPdfUaCompliant in interface IDocument
        Returns:
        boolean value
      • isXrefGapsAllowed

        public boolean isXrefGapsAllowed()

        Gets or sets the is document pdfa compliant.

        Specified by:
        isXrefGapsAllowed in interface IDocument
        Returns:
        boolean value
      • setXrefGapsAllowed

        public void setXrefGapsAllowed(boolean value)

        Gets or sets the is document pdfa compliant.

        Specified by:
        setXrefGapsAllowed in interface IDocument
        Parameters:
        value - boolean value
      • getEmbedStandardFonts

        public boolean getEmbedStandardFonts()

        Property which declares that document must embed all standard Type1 fonts which has flag IsEmbedded set into true. All PDF fonts can be embedded into document simply via setting of flag IsEmbedded into true, but PDF standard Type1 fonts is an exception from this rule. Standard Type1 font embedding requires much time, so to embed these fonts it's necessary not only set flag IsEmbedded into true for specified font but also set an additiona flag on document's level - EmbedStandardFonts = true; This property can be set only one time for all fonts. By default false.

        Specified by:
        getEmbedStandardFonts in interface IDocument
        Returns:
        boolean value
      • setEmbedStandardFonts

        public void setEmbedStandardFonts(boolean value)

        Property which declares that document must embed all standard Type1 fonts which has flag IsEmbedded set into true. All PDF fonts can be embedded into document simply via setting of flag IsEmbedded into true, but PDF standard Type1 fonts is an exception from this rule. Standard Type1 font embedding requires much time, so to embed these fonts it's necessary not only set flag IsEmbedded into true for specified font but also set an additiona flag on document's level - EmbedStandardFonts = true; This property can be set only one time for all fonts. By default false.

        Specified by:
        setEmbedStandardFonts in interface IDocument
        Parameters:
        value - boolean value
      • removePdfUaCompliance

        public void removePdfUaCompliance()

        Remove pdfUa compliance from the document

        Specified by:
        removePdfUaCompliance in interface IDocument
      • setTitle

        public final void setTitle(String title)

        Set Title for Pdf Document

        Specified by:
        setTitle in interface IDocument
        Parameters:
        title - Document's title
      • preSave

        public static void preSave(PageCollection pages,
                                   SaveOptions saveOptions)
        Internal method
        Parameters:
        pages - PageCollection instance
        saveOptions - SaveOptions instance
      • setConvertMetadataAndCatalogOnly

        public final void setConvertMetadataAndCatalogOnly(boolean value)

        Gets convert parameter for pdf/ua converter (Convert only Metadata and Document Catalog if set true)

        Specified by:
        setConvertMetadataAndCatalogOnly in interface IDocument
        Parameters:
        value - boolean value
      • getDuplex

        public int getDuplex()

        Gets or sets print duplex mode handling option to use when printing the file from the print dialog.

        Specified by:
        getDuplex in interface IDocument
        Returns:
        PrintDuplex element
        See Also:
        PrintDuplex
      • setDuplex

        public void setDuplex(int value)

        Gets or sets print duplex mode handling option to use when printing the file from the print dialog.

        Specified by:
        setDuplex in interface IDocument
        Parameters:
        value - PrintDuplex element
        See Also:
        PrintDuplex
      • save

        public void save(com.aspose.ms.System.IO.FileStream output)
      • exportAnnotationsToXfdf

        public final void exportAnnotationsToXfdf(OutputStream output)

        Export all document annotations into stream.

        Parameters:
        output - Stream where store XFDF.
      • importAnnotationsFromXfdf

        public final void importAnnotationsFromXfdf(InputStream stream)

        Imports annotations from stream to document.

        Parameters:
        stream - Stream contains XFDF data.
      • convert

        public final boolean convert(OutputStream outputLogStream,
                                     int format,
                                     int action,
                                     int transparencyAction)

        Convert document and save errors into the specified file.

        Parameters:
        outputLogStream - Stream where the comments will be stored.
        format - The pdf format.
        action - Action for objects that can not be converted
        transparencyAction - Action for image masked objects
        Returns:
        The operation result
      • convertPageToPNGMemoryStream

        public byte[] convertPageToPNGMemoryStream(Page page)
        Convert page to PNG for DSR, OMR , OCR
        Parameters:
        page - Page object
        Returns:
        byte[] array.
      • validate

        public boolean validate(PdfFormatConversionOptions options)

        Validate document into the specified file.

        Parameters:
        options - set of options for convert PDF document
        Returns:
        The operation result
      • convert

        public boolean convert(Document.CallBackGetHocr callback,
                               boolean isTestVisible)
        Convert document and save errors into the specified file.

        This is allow to show/hide searchable text. Default value is FALSE.

        Specified by:
        convert in interface IDocument
        Parameters:
        callback - Action for objects that can not be converted
        isTestVisible - boolean value
        Returns:
        The operation result
      • convert

        public boolean convert(Document.CallBackGetHocr callback,
                               boolean isTextVisible,
                               boolean isOriginalImage)
        Convert document and save errors into the specified file.

        This is allow to show/hide searchable text on page. Default value is FALSE. This is allow to getting original image from pdf. Default value is FALSE.

        Specified by:
        convert in interface IDocument
        Parameters:
        callback - Action for objects that can not be converted
        isTextVisible - boolean value
        isOriginalImage - boolean value
        Returns:
        The operation result
      • convert

        public static void convert(String srcFileName,
                                   LoadOptions loadOptions,
                                   String dstFileName,
                                   SaveOptions saveOptions)

        Converts source file in source format into destination file in destination format.

        Parameters:
        srcFileName - The source file name.
        loadOptions - The source file format.
        dstFileName - The destination file name.
        saveOptions - The destination file format.
      • convert

        public static void convert(InputStream srcStream,
                                   LoadOptions loadOptions,
                                   String dstFileName,
                                   SaveOptions saveOptions)

        Converts stream in source format into destination file in destination format.

        Parameters:
        srcStream - The source stream.
        loadOptions - The source stream format.
        dstFileName - The destination file name.
        saveOptions - The destination file format.
      • convert

        public static void convert(String srcFileName,
                                   LoadOptions loadOptions,
                                   OutputStream dstStream,
                                   SaveOptions saveOptions)

        Converts source file in source format into stream in destination format.

        Parameters:
        srcFileName - The source file name.
        loadOptions - The source file format.
        dstStream - The destination stream.
        saveOptions - The destination stream format.
      • convert

        public static void convert(InputStream srcStream,
                                   LoadOptions loadOptions,
                                   OutputStream dstStream,
                                   SaveOptions saveOptions)

        Converts stream in source format into stream in destination format.

        Parameters:
        srcStream - The source stream.
        loadOptions - The source stream format.
        dstStream - The destination stream.
        saveOptions - The destination file format.
      • flatten

        public void flatten(Form.FlattenSettings flattenSettings)

        Removes all fields from the document and place their values instead.

        Parameters:
        flattenSettings - Settings for flattening process.
      • updatePages

        public void updatePages()
        Description copied from interface: IDocument
        updatePages
        Specified by:
        updatePages in interface IDocument
      • close

        public void close()

        Closes all resources used by this document.

        Specified by:
        close in interface IDocument
      • optimizeResources

        public void optimizeResources(OptimizationOptions strategy)

        Optimize resources in the document according to defined optimization strategy.

        Specified by:
        optimizeResources in interface IDocument
        Parameters:
        strategy - Optimization strategy.
      • getAllowReusePageContent

        public boolean getAllowReusePageContent()

        Allows to merge page contents to optimize docuement size. If used then differnet but duplicated pages may reference to the same content object. Please note that this mode may cause side effects like changing page content when other page is changed.

        Returns:
        value boolean value
      • setAllowReusePageContent

        public void setAllowReusePageContent(boolean value)

        Allows to merge page contents to optimize docuement size. If used then differnet but duplicated pages may reference to the same content object. Please note that this mode may cause side effects like changing page content when other page is changed.

        Parameters:
        value - boolean value
      • afterImport

        public void afterImport()

        Enumerate all registered annotations and call AfterImport for each of them. InternalMethod

        Specified by:
        afterImport in interface IDocument
      • saveXml

        public void saveXml(String file)

        Save document to XML.

        Specified by:
        saveXml in interface IDocument
        Parameters:
        file - The document model xml file
      • getObjectById

        public Object getObjectById(String id)

        Gets a object with specified ID in the document.

        Specified by:
        getObjectById in interface IDocument
        Parameters:
        id - The object id.
        Returns:
        The object with specified id. Null if the id is not found.
      • bindXml

        public void bindXml(InputStream stream)

        Bind xml to document

        Specified by:
        bindXml in interface IDocument
        Parameters:
        stream - The stream with xml file
      • bindXml

        public void bindXml(String file)

        Bind xml to document

        Specified by:
        bindXml in interface IDocument
        Parameters:
        file - The xml file
      • repair

        public void repair()
        Repairs broken document.
        Specified by:
        repair in interface IDocument
      • bindXml

        public void bindXml(String xmlFile,
                            String xslFile)

        Bind xml/xsl to document

        Specified by:
        bindXml in interface IDocument
        Parameters:
        xmlFile - The xml file.
        xslFile - The xsl file if XSLT is used.
      • bindXml

        public void bindXml(InputStream xmlStream,
                            InputStream xslStream)

        Bind xml/xsl to document

        Parameters:
        xmlStream - The xml stream.
        xslStream - The xsl stream if XSLT is used.
      • bindXml

        public void bindXml(InputStream xmlStream,
                            InputStream xslStream,
                            com.aspose.ms.System.Xml.XmlReaderSettings settings)

        Bind xml/xsl to document

        Parameters:
        xmlStream - The xml stream.
        xslStream - The xsl stream if XSLT is used.
        settings - The xml reader settings.
      • getXmpMetadata

        public void getXmpMetadata(OutputStream output)

        Get XMP metadata from document.

        Specified by:
        getXmpMetadata in interface IDocument
        Parameters:
        output - Stream where metadata will be stored.
      • setXmpMetadata

        public void setXmpMetadata(InputStream stream)

        Set XMP metadata of document.

        Specified by:
        setXmpMetadata in interface IDocument
        Parameters:
        stream - Stream which contains XMP metadata.
      • isEnableObjectUnload

        public boolean isEnableObjectUnload()

        Get or sets flag which enables document partially be unloaded from memory. This allow to decrease memory usage but may have negative effect on perofmance.

        Returns:
        boolean value
      • setEnableObjectUnload

        public void setEnableObjectUnload(boolean value)

        Get or sets flag which enables document partially be unloaded from memory. This allow to decrease memory usage but may have negative effect on perofmance.

        Parameters:
        value - boolean value
      • getTaggedContent

        public final ITaggedContent getTaggedContent()

        Gets access to TaggedPdf content.

        The example demonstrates how to use tagged content for creating new document with header, paragraphs and images.

             // Create new document
             Document document = new Document();
        
             // Get the tagged content
             ITaggedContent taggedContent = document.getTaggedContent();
        
             // Set language for document
             taggedContent.setLanguage("en-US");
        
             // Set title for PDF document
             taggedContent.setTitle("Example document");
        
             // Creating and adding Section
             SectElement sect = taggedContent.createSectElement();
             taggedContent.getRootElement().appendChild(sect);
        
             // Create Header
             HeaderElement h1 = taggedContent.createHeaderElement(1);
             h1.setText("The Header");
             sect.appendChild(h1);
        
             // Create paragraph
             ParagraphElement p = taggedContent.createParagraphElement();
             p.setTag("Paragraph");
             p.setText("The text of paragraph.");
             sect.appendChild(p);
             // Create illustration
             IllustrationElement figure1 = taggedContent.createFigureElement();
             sect.appendChild(figure1);
             figure1.setAlternativeText("Figure 1");
             figure1.setTitle("Image 1");
             figure1.setTag("Fig");
             figure1.setImage("path/of/image.jpg");
             // Save document
             document.save("example.pdf");
         
        Returns:
        ITaggedContent instamce