|
| 1 | +unit PDFInst; |
| 2 | + |
| 3 | +interface |
| 4 | +uses |
| 5 | + System.SysUtils, PDFXEdit_TLB; |
| 6 | + |
| 7 | +type |
| 8 | + TInst = class |
| 9 | + private |
| 10 | + { private declarations } |
| 11 | + protected |
| 12 | + { protected declarations } |
| 13 | + public |
| 14 | + { public declarations } |
| 15 | + FInst: PDFXEdit_TLB.IPXV_Inst; |
| 16 | + FInstCore: PDFXEdit_TLB.IPXC_Inst; |
| 17 | + FInstAUX: IAUX_Inst; |
| 18 | + |
| 19 | + constructor Create; |
| 20 | + destructor Destroy; override; |
| 21 | + |
| 22 | + procedure Init(inst: PDFXEdit_TLB.IPXV_Inst); |
| 23 | + procedure InsertEmptyPage(doc: PDFXEdit_TLB.IPXV_Document; nPage: integer; nCount: integer); |
| 24 | + procedure DeletePages(doc: PDFXEdit_TLB.IPXV_Document; nPageStart, nPageStop: integer); |
| 25 | + |
| 26 | + procedure InsertPagesTest(); |
| 27 | + published |
| 28 | + { published declarations } |
| 29 | + end; |
| 30 | + |
| 31 | +var |
| 32 | + gInst: TInst; |
| 33 | + |
| 34 | +implementation |
| 35 | + |
| 36 | +{ TInst } |
| 37 | + |
| 38 | +constructor TInst.Create; |
| 39 | +begin |
| 40 | + inherited; |
| 41 | + FInst := nil; |
| 42 | +end; |
| 43 | + |
| 44 | +destructor TInst.Destroy; |
| 45 | +begin |
| 46 | + FInst := nil; |
| 47 | + inherited; |
| 48 | +end; |
| 49 | + |
| 50 | +procedure TInst.Init(inst: PDFXEdit_TLB.IPXV_Inst); |
| 51 | +begin |
| 52 | + FInst := inst; |
| 53 | + FInstCore := FInst.GetExtension('PXC') as PDFXEdit_TLB.IPXC_Inst; |
| 54 | + FInstAUX := FInstCore.GetExtension('AUX') as IAUX_Inst; |
| 55 | + |
| 56 | +end; |
| 57 | + |
| 58 | +procedure TInst.DeletePages(doc: PDFXEdit_TLB.IPXV_Document; nPageStart, |
| 59 | + nPageStop: integer); |
| 60 | +var |
| 61 | + nID: integer; |
| 62 | + pOp: PDFXEdit_TLB.IOperation; |
| 63 | + input: PDFXEdit_TLB.ICabNode; |
| 64 | + options: PDFXEdit_TLB.ICabNode; |
| 65 | +begin |
| 66 | + nID := FInst.Str2ID('op.document.deletePages', false); |
| 67 | + pOp := FInst.CreateOp(nID); |
| 68 | + input := pOp.Params.Root['Input']; |
| 69 | + input.v := Doc; |
| 70 | + options := pOp.Params.Root['Options']; |
| 71 | + options['PagesRange.Type'].v := 'Exact'; |
| 72 | + options['PagesRange.Text'].v := Format('%d-%d', [nPageStart, nPageStop]) ; //Select pages range that will be deleted from the document |
| 73 | + pOp.Do_(0); |
| 74 | +end; |
| 75 | + |
| 76 | +procedure TInst.InsertEmptyPage(doc: PDFXEdit_TLB.IPXV_Document; nPage, |
| 77 | + nCount: integer); |
| 78 | +var |
| 79 | + nID: integer; |
| 80 | + pOp: PDFXEdit_TLB.IOperation; |
| 81 | + input: PDFXEdit_TLB.ICabNode; |
| 82 | + options: PDFXEdit_TLB.ICabNode; |
| 83 | +begin |
| 84 | + nID := FInst.Str2ID('op.document.insertEmptyPages', False); |
| 85 | + pOp := FInst.CreateOp(nID); |
| 86 | + input := pOp.Params.Root['Input']; |
| 87 | + input.v := Doc; |
| 88 | + options := pOp.Params.Root['Options']; |
| 89 | + options['PaperType'].v := 2; //Apply custom paper type |
| 90 | + options['Count'].v := nCount; //Create nCount new pages |
| 91 | + options['Width'].v := 800; //Width of new pages |
| 92 | + options['Height'].v := 1200; //Height of new pages |
| 93 | + options['Location'].v := 1; //New pages will be inserted after first page |
| 94 | + options['Position'].v := nPage; //Page number |
| 95 | + pOp.Do_(0); |
| 96 | +end; |
| 97 | + |
| 98 | +procedure TInst.InsertPagesTest; |
| 99 | +var |
| 100 | + AFile1, AFile2: String; |
| 101 | + ADoc1, ADoc2: IPXC_Document; |
| 102 | + BS: IBitSet; |
| 103 | + APageCount1, APageCount2: Cardinal; |
| 104 | +begin |
| 105 | + AFile1 := 'F:\TEMP\Numbers.pdf'; |
| 106 | + AFile2 := 'F:\TEMP\Letters.pdf'; |
| 107 | + try |
| 108 | + ADoc1 := FInstCore.OpenDocumentFromFile(PChar(AFile1), nil, nil, 0, 0); |
| 109 | + ADoc2 := FInstCore.OpenDocumentFromFile(PChar(AFile2), nil, nil, 0, 0); |
| 110 | + |
| 111 | + ADoc1.Pages.Get_Count(APageCount1); |
| 112 | + ADoc2.Pages.Get_Count(APageCount2); |
| 113 | + |
| 114 | + BS := FInstAUX.CreateBitSet(APageCount2); |
| 115 | + BS.SetSize(APageCount2); |
| 116 | + BS.Item[0] := True; |
| 117 | + BS.Item[1] := True; |
| 118 | + ADoc1.Pages.InsertPagesFromDocEx(ADoc2, APageCount1, BS, IPF_Annots_Copy + IPF_Bookmarks_CopyAll, nil); |
| 119 | + ADoc1.WriteToFile(PChar(AFile1), nil, 0); |
| 120 | + finally |
| 121 | + end; |
| 122 | +end; |
| 123 | + |
| 124 | +begin |
| 125 | + gInst := TInst.Create; |
| 126 | +end. |
0 commit comments