The Save method saves the current PDF document to a file.
Sub Save(FileName As String, SaveOption As FileSaveOptionConstants)
void Save(string FileName, FileSaveOptionConstants SaveOption)
HRESULT Save(BSTR FileName, FileSaveOptionConstants SaveOption)
FileName
Name of the file where to save the document.
SaveOption
This option specifies what data to write in the saved document. The SaveOption is of type FileSaveOptionConstants which is defined as follows:
Option |
Value |
Description |
---|---|---|
acFileSaveAll |
0 |
Save document data and view. This option should be only used with PDF created by Amyuni PDF Creator. The document can be viewed with any PDF viewer and retains all design data. |
acFileSaveView |
1 |
Save only document view. The document can be viewed with any PDF viewer including Amyuni PDF Creator but all design data such as database connection, OLE objects, is lost. |
acFileSaveDesign |
2 |
Save only document data. The document can be opened, viewed and edited only with the Amyuni PDF Creator. It will show as blank pages in other viewers. |
acFileSaveDefault |
-1 |
Take the default Save option stored in the document object, i.e., one of the 3 options above. |
acFileSavePDFA_7 |
3 |
[Obsolete]. |
acFileSavePDFA |
4 |
Save document in PDF/A format. |
acFileSavePDF14 |
5 |
Save document PDF Specifications Version 1.4. |
acFileSavePDFUA
|
6 |
Save the file with XMP metadata compatible with PDF/UA |
For acFileSavePDFUA needs to set the PDFALevel to 1 (PDFA-1). This is for future development and support for higher versions of PDF/UA. So the same level attribute is used for PDF/A and PDF/UA.
We still need to set the ViewerPreferences and DocumentLanguage for PDF/UA, these will not be created automatically:
pdf.ObjectAttribute("Document", "ViewerPreferences") = "/DisplayDocTitle true"
pdf.ObjectAttribute("Document", "DocumentLanguage") = "en"
pdf.ObjectAttribute("Document", "FileSaveOption") = acFileSavePDFUA
This method uses the PageSequence or PageSecuenceStr attributes from Document Object to determine which pages are going to be saved to the PDF file.
For more information about the OCRDataFilesLocation and OCRWithTesseract305, please, check the Document attributes page.
Sub Sample()
' Constants for Activation codes
Const strLicenseTo As String = "Amyuni PDF OCR Module Evaluation"
Const strActivationCode As String = "07EFCDAB010001005A888A7BCB912FAF9284F5623992DE32607C682FED0215DC171A7C2DFC70738C3B9BD6718DA5BB4A837D98E783BF"
' Initializing PDFCreativeX Object
Dim pdf As ACPDFCREACTIVEX.PDFCreactiveX = New ACPDFCREACTIVEX.PDFCreactiveX()
' Set license key
pdf.SetLicenseKey(strLicenseTo, strActivationCode)
' Open an existent PDF file
Dim fileName As String = "c:\temp\PDFdocument.pdf"
Dim password As String = ""
pdf.Open(fileName, password)
' OCR configuration
pdf.ObjectAttribute("Document", "OCRDataFilesLocation") = "C:\Tesseract41"
' OCR
Dim startPage As Integer = 1
Dim endPage As Integer = pdf.PageCount
Dim language As String = "eng"
pdf.OCRPageRange(startPage, endPage, language, ACPDFCREACTIVEX.acOCROptions.acOCROptionVisibleText)
' Save PDF
pdf.Save("c:\temp\CreatePDFDocument_resulting.pdf", ACPDFCREACTIVEX.FileSaveOptionConstants.acFileSaveView)
' destroy objects
pdf = Nothing
End Sub
static void Sample()
{
const string strLicenseTo = "Amyuni PDF OCR Module Evaluation";
const string strActivationCode = "07EFCDAB010001005A888A7BCB912FAF9284F5623992DE32607C682FED0215DC171A7C2DFC70738C3B9BD6718DA5BB4A837D98E783BF";
// Initializing PDFCreativeX Object
ACPDFCREACTIVEX.PDFCreactiveX pdf = new ACPDFCREACTIVEX.PDFCreactiveX();
// Set license key
pdf.SetLicenseKey(strLicenseTo, strActivationCode);
// Open an existent PDF file
string fileName = @"c:\temp\PDFdocument.pdf";
string password = "";
pdf.Open(fileName, password);
// OCR configuration
pdf.ObjectAttribute("Document", "OCRDataFilesLocation") = @"C:\Tesseract41";
// OCR
int startPage = 1;
int endPage = pdf.PageCount;
string language = "eng";
pdf.OCRPageRange(startPage, endPage, language, ACPDFCREACTIVEX.acOCROptions.acOCROptionVisibleText);
// Save PDF
pdf.Save(@"c:\temp\CreatePDFDocument_resulting.pdf", ACPDFCREACTIVEX.FileSaveOptionConstants.acFileSaveView);
// destroy objects
pdf = null;
}
#include <iostream>
#import "c:\users\amyuni\pdfcreactivex.dll" no_namespace
using namespace std;
int main()
{
// Constants for Activation codes
bstr_t strLicenseTo = "Amyuni PDF OCR Module Evaluation";
bstr_t strActivationCode = "07EFCDAB010001005A888A7BCB912FAF9284F5623992DE32607C682FED0215DC171A7C2DFC70738C3B9BD6718DA5BB4A837D98E783BF";
// Initialize the COM subsystem
CoInitialize(0);
// IPDFCreactiveXPtr is a smart pointer type defined in pdfcreactivex.tlh,
// the type library header file generated by the #import instruction above
IPDFCreactiveXPtr pdf;
// Create the PDFCreactiveX instance
pdf.CreateInstance(__uuidof(PDFCreactiveX));
// set license key
pdf->SetLicenseKey(_bstr_t(strLicenseTo), _bstr_t(strActivationCode));
// Open an existent PDF file
_bstr_t fileName = "c:\\temp\\PDFdocument.pdf";
_bstr_t password = "";
pdf->Open(fileName, password);
// OCR configuration
pdf->PutObjectAttribute("Document", "OCRDataFilesLocation", "C:\\Tesseract41");
// OCR
int startPage = 1;
int endPage = pdf->PageCount;
_bstr_t language = "eng";
pdf->OCRPageRange(startPage, endPage, language, acOCROptionVisibleText);
// Save PDF
pdf->Save("c:\\temp\\CreatePDFDocument_resulting.pdf", acFileSaveView);
// destroy objects
pdf = NULL;
return 0;
}
' OCR options
Const acOCROptionVisibleText = 1
' FileSaveOptionConstants
Const acFileSaveAll = 0
Const acFileSaveDefault = -1
Const acFileSaveView = 1
Const acFileSaveDesign = 2
Const acFileSavePDFA_7 = 3
Const acFileSavePDFA = 4
Const acFileSavePDF14 = 5
' Constants for Activation codes
Const strLicenseTo = "Amyuni PDF OCR Module Evaluation"
Const strActivationCode = "07EFCDAB010001005A888A7BCB912FAF9284F5623992DE32607C682FED0215DC171A7C2DFC70738C3B9BD6718DA5BB4A837D98E783BF"
' Initializing PDFCreativeX Object
Dim pdf
Set pdf = CreateObject("PDFCreactiveX.PDFCreactiveX.6.5")
' Set license key
pdf.SetLicenseKey strLicenseTo, strActivationCode
' Open an existent PDF file
Dim fileName
fileName = "c:\temp\ocrtest.pdf"
Dim password
password = ""
pdf.Open fileName, password
' OCR configuration
pdf.ObjectAttributeStr "Document", "OCRDataFilesLocation", "C:\Tesseract41"
' OCR
Dim startPage
startPage=1
Dim endPage
endPage = pdf.PageCount
Dim language
language = "eng"
pdf.OCRPageRange startPage, endPage, language, acOCROptionVisibleText
' Save PDF using StartSave, SavePage and EndSave
pdf.Save "c:\temp\ocred.pdf", acFileSaveView
' destroy Objects
Set pdf = Nothing
Important Note
All the samples that are provided in this documentation assume that the developer is using the ActiveX version (PDFCreactiveX.dll.)
When using the .NET version (acPDFCreatorLib.Net.Dll), the functions are very similar although the code slightly different. Rather than duplicating all the documentation and sample code, we have chosen to provide a complete .NET sample at the end of this documentation.