Save PDF document programmatically

The next code snippet also works with a new graphical Aspose.Drawing interface.

Save PDF document to file system

You can save the created or manipulated PDF document to file system using Save method of Document class. When you do not provide the format type (options), then the document is saved in Aspose.PDF v.1.7 (*.pdf) format.

public static void SaveDocument()
{
    var originalFileName = Path.Combine(_dataDir, "SimpleResume.pdf");
    var modifiedFileName = Path.Combine(_dataDir, "SimpleResumeModified.pdf");

    var pdfDocument = new Aspose.Pdf.Document(originalFileName);
    // make some manipation, i.g add new empty page
    pdfDocument.Pages.Add();
    pdfDocument.Save(modifiedFileName);
}

Save PDF document to stream

You can also save the created or manipulated PDF document to stream by using overloads of Save methods.

public static void SaveDocumentStream()
{
    var originalFileName = Path.Combine(_dataDir, "SimpleResume.pdf");
    var modifiedFileName = Path.Combine(_dataDir, "SimpleResumeModified.pdf");

    var pdfDocument = new Aspose.Pdf.Document(originalFileName);
    // make some manipation, i.g add new empty page
    pdfDocument.Pages.Add();
    pdfDocument.Save(System.IO.File.OpenWrite(modifiedFileName));
}

Save PDF document in Web applications

To save documents in Web applications, you can use the ways proposed above. In addition, the Document class has overloaded method Save for using with the HttpResponse class.

var originalFileName = Path.Combine(_dataDir, "SimpleResume.pdf");
var pdfDocument = new Aspose.Pdf.Document(originalFileName);
// make some manipulation, i.g add a new empty page
pdfDocument.Pages.Add();
pdfDocument.Save(Response, originalFileName, ContentDisposition.Attachment, new PdfSaveOptions());

For more detailed explanation please follow to Showcase section.

Save PDF/A or PDF/X format

PDF/A is an ISO-standardized version of the Portable Document Format (PDF) for use in archiving and long-term preservation of electronic documents. PDF/A differs from PDF in that it prohibits features not suitable for long-term archiving, such as font linking (as opposed to font embedding) and encryption. ISO requirements for PDF/A viewers include color management guidelines, embedded font support, and a user interface for reading embedded annotations.

PDF/X is a subset of the PDF ISO standard. The purpose of PDF/X is to facilitate graphics exchange, and it therefore has a series of printing-related requirements which do not apply to standard PDF files.

In both cases, the Save method is used to store the documents, while the documents must be prepared using the Convert method.

public static void SaveDocumentAsPDFx()
{
    var pdfDocument = new Aspose.Pdf.Document("..\\..\\..\\Samples\\SimpleResume.pdf");
    pdfDocument.Pages.Add();
    pdfDocument.Convert(new PdfFormatConversionOptions(PdfFormat.PDF_X_3));
    pdfDocument.Save("..\\..\\..\\Samples\\SimpleResume_X3.pdf");
}