I use this code to import and save PDF file
Code: Select all
int pages = pdf.SetSourceFile(szInFile);
for (int i=1; i<=pages; i++)
tpl = pdf.ImportPage(i);
but size of output file is not the same as original, and page orientation is always A4 portret
How should wxPdfDocument guess what you intend to do? wxPdfDocument does what you tell it to do.
If you don't specify a page orientation and page size on instantiating a wxPdfDocument object, you get A4 portrait
as the default. The page orientation and the page size can be specified either in the constructor as the default for the whole document or in method AddPage for each individual page.
cutecode wrote:How to make a precise copy of PDF?
Thinking heretically I'd say "Just copy the original PDF file to a new destination using the wxCopyFile
If you want to extract pages from an existing PDF file and insert an exact copy into a new document, you have to take appropriate action:
- Use ImportPage with second parameter wxPDF_PAGEBOX_MEDIABOX to get the physical page
- Use GetTemplateSize to determine the width and height of the imported page
- If you know that all pages in the existing document have the same size, instantiate a wxPdfDocument with the page size determined in the previous step. Otherwise use AddPage with page size parameters for each page
- Finally use UseTemplate with explicit positioning to coordinate (0,0)