<< Click to Display Table of Contents >> Navigation: Commands > Save PDF |
WPViewPDF PLUS can also save the loaded PDF data to a new PDF file.
This makes sense if you need to merge multiple PDF files into a new file, if you need to delete certain pages, if you changed info strings or added or removed encryption.
Unlike some competing products, WPViewPDF PLUS 3 checks all exported pages for used images and fonts - and only exports the fonts and images which are actually used.
A PDF viewer has to respect the PDF security, so does our viewing component.
If security settings of a PDF file forbid saving, the component will not save.
You as the developer can override this at Your own risk.
Use command(COMPDF_DisableSecurityOverride,1) to disable this check.
This pascal code saves all pages in the PDF to individual files:
WPViewPDF1.CommandEx(COMPDF_DisableSecurityOverride,1);
for cnt := 0 to WPViewPDF1.PageCount-1 do
begin
WPViewPDF1.SelectPage(0,0); //Clear
WPViewPDF1.SelectPage(1,cnt); // add #cnt
WPViewPDF1.PLUS.SaveSelectionToFile('s:\page' + IntToStr(cnt) + '.pdf');
end;
When extracting text from a PDF file WPViewPDF will first sort the text element using their horizontal coordinate. This can be switched off using COMPDF_TextExtractDontSort.
It is possible to disable saving using command(COMPDF_DisableSave). It is not possible to enable it again.
To check wether the PDF file may be saved, use command
COMPDF_MaySavePDF = 500.
If Result > 0 the document may be saved (it is not protected).
COMPDF_CheckOwnerPassword = 291
Checks if the given password (StrParam) matches the owner password.
If yes, the security is cleared and TRUE is returned.
The commands below are used for saving.
When using the VCL it is better to use the high level save methods.
COMPDF_SaveToFile = 501
Save the combined contents to file.
COMPDF_SaveToEStream = 497
Save to event stream. Result = count of saved pages.
COMPDF_SaveSelectionToEStream = 498
Save selected pages to event stream. (Used internally in Delphi VCL - see load commands)
COMPDF_SaveSelectionToFile = 511
Save selected pages to a file.
COMPDF_SaveToIStream = 513
Save to IStream, must be passed as IUnknown reference
COMPDF_SaveSelectionToIStream = 514
Save selected pages to IStream, must be passed as IUnknown reference
COMPDF_SetSaveMode = 613
Set the save mode. It is possible to use this bits:
1: Remove the Annots except for Hyperlinks. Ommits "AcroForm"
2: Remove the Hyperlinks
4: Remove the Bookmarks
8: Remove the StructElements
16: Remove Transition Effects
32: remove Page AA Actions
64: remove PDFA flag
128: Delete Extra XML Data
256: Delete extra commands (such as images and DrawObjects)
512: Delete named destinations
1024: Do not create PDF/A Marker
2048: Do always create PDF/A Marker
4096: Do not save modified page sizes
8192: Never write Cropbox parameter
// To save a scaled PDF use: COMPDF_SaveScaledPDFMode !
8192*2 Delete extra commands (such as images and DrawObjects)
8192*4 Delete named destinations
8192*8 DO not create PDF A Marker
8192*16 DO always create PDF A Marker
8192*32 Don't modify page Size
8192*64 Flatten the PDF on save time. This requires that proper Appearance streams are present for the Fields.
COMPDF_GetModified = 515
Read state of internal "Modified" flag. With IntPar=1000 the modified flag will be also cleared.
The modified flag is set by the page deletion, rotation and page moving commands and actions.
This commands are used to set the security features of the saved PDF
COMPDF_SetSecurityMode = 507
Set security when saving 0=off, 1=40 bit, 2=128 bit RC4
COMPDF_SetSecurityFlags= 508
Set the "P flags" bitfield.
To disable a feature the bit must be clear
Bit 3 = printing
Bit 4 = modification
Bit 5 = allow copy and extract
Bit 6 = add annotations
COMPDF_SetSecurityUser = 509
StrParam is the user password.
COMPDF_SetSecurityOwner= 510
StrParam is the owner password.
COMPDF_GetTextLen=260, COMPDF_GetTextBuf=261
Get the page text as character buffer as ANSI, RTF, TXT, HTML and XML.
bufsize = Command(COMPDF_GetTextLen, format, PageNo);
CommandEx(COMPDF_GetTextBuf, ansi_buffer);
(also see: TWPViewPDF.GetPageText Method )
It is possible to limit the area where the text is extracted by specifying a rectangle, x,y,x1,y1.
Please note that the values are measured in 72dpi and are not using any rotation which may be applied to the PDF page.
COMPDF_GetTextSetOptions = 272; // Bitfield:
// bit 2=2: xyhtml writes Y position as baseline position. Default = 2 = on
// bit 3=4: activate/deactivate the GetTextFilterRect
COMPDF_GetTextFilterRectX = 273;
COMPDF_GetTextFilterRectY = 274;
COMPDF_GetTextFilterRectX1 = 275;
COMPDF_GetTextFilterRectY1 = 276;
COMPDF_CopyToClibrd = 268;
Copy selected text to clipboard (RTF, ANSI, UNICODE format). Result = length. (same as Ctrl+C)
if Bit 1 is set in IntParam, the complete text and images are copied
if Bit 2 is set in IntParam, the complete text and images on current page are copied
If bit 3 is set, the complete page will be copied as bitmap (high word = resolution, default = screen dpi)
If bit 4 is set, only the text inside the drawn rectangle will be copied. Use with COMPDF_SelectMode, 2
COMPDF_MODIFIED = 601
The command is used to retrieve the "modified" bit field.
This values are used:
1 Append PDF,
2 Move Page,
4 Delete Page,
8 Add Object or Annotation
16 Move Object or Annotation
32 Object Properties,
64 Delete Object,
128 Delete Acrofield,
256 Edit Tx Annotation (edit, memo)
512 Edit CH Annotation (checkbox)
1024 Add Attachment,
2048 Add XMP Information
You can pass 1 as integer parameter to set deactivate all bits. If the user is able to edit annotations it is recommended to always save the PDF as a new version since there are other ways to modify annotations not covered by Modified.