using System; using System.Text; using System.Runtime.InteropServices; using iTextSharp.text.pdf; using iTextSharp.text; using System.IO; namespace DyconPDFMerger { [ComVisible(true)] [ProgId("DyconPDFMerger")] [ClassInterface(ClassInterfaceType.AutoDual)] public class Main { public String MergeFiles(string saveToFilename, string inputFileDirectory, string filesSeperatedBySemiColon) { String output = saveToFilename; string[] files = filesSeperatedBySemiColon.Split(';'); for (int i = 0; i < files.Length; i++) { files[i] = inputFileDirectory + files[i]; } Merge(saveToFilename, files); return output; } public String MergeFiles(string saveToFilename, string[] files) { String output = saveToFilename; Merge(saveToFilename, files); return output; } public void OpenFile(string filename) { if (string.IsNullOrEmpty(filename)) { throw new Exception("Empty filename"); } System.Diagnostics.Process.Start(@filename); } private void Merge(string destinationFile, string[] sourceFiles) { try { int f = 0; // we create a reader for a certain document PdfReader reader = new PdfReader(sourceFiles[f]); // we retrieve the total number of pages int n = reader.NumberOfPages; //Console.WriteLine("There are " + n + " pages in the original file."); // step 1: creation of a document-object Document document = new Document(reader.GetPageSizeWithRotation(1)); // step 2: we create a writer that listens to the document PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(destinationFile, FileMode.Create)); // step 3: we open the document document.Open(); PdfContentByte cb = writer.DirectContent; PdfImportedPage page; int rotation; // step 4: we add content while (f < sourceFiles.Length) { int i = 0; while (i < n) { i++; document.SetPageSize(reader.GetPageSizeWithRotation(i)); document.NewPage(); page = writer.GetImportedPage(reader, i); rotation = reader.GetPageRotation(i); if (rotation == 90 || rotation == 270) { cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height); } else { cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0); } //Console.WriteLine("Processed page " + i); } f++; if (f < sourceFiles.Length) { reader = new PdfReader(sourceFiles[f]); // we retrieve the total number of pages n = reader.NumberOfPages; //Console.WriteLine("There are " + n + " pages in the original file."); } } // step 5: we close the document document.Close(); } catch (Exception e) { string strOb = e.Message; } } private int CountPageNo(string strFileName) { // we create a reader for a certain document PdfReader reader = new PdfReader(strFileName); // we retrieve the total number of pages return reader.NumberOfPages; } } }
CLEAR(SalesInvoiceReport); CLEAR(DyconTimerReport); CLEAR(DyconUtgiftReport); SalesInvoiceReport.USEREQUESTFORM(FALSE); DyconTimerReport.USEREQUESTFORM(FALSE); DyconUtgiftReport.USEREQUESTFORM(FALSE); EVALUATE(tempDate, '01' + COPYSTR(FORMAT(TODAY), 3, STRLEN(FORMAT(TODAY)))) ; tempDate := CALCDATE('<+1M>', tempDate); tempDate := CALCDATE('<-1D>', tempDate); DyconTimer.SETFILTER(DyconTimer.Kunde, "Bill-to Customer No."); DyconTimer.SETFILTER(DyconTimer.Arbeidsdato, '01' + COPYSTR(FORMAT(TODAY), 3, STRLEN(FORMAT(TODAY))) + '..' + FORMAT(tempDate)); DyconUtgifter.SETFILTER(DyconUtgifter.Kunde, "Bill-to Customer No."); DyconUtgifter.SETFILTER(DyconUtgifter.Innleggsdato, '01' + COPYSTR(FORMAT(TODAY), 3, STRLEN(FORMAT(TODAY))) + '..' + FORMAT(tempDate)); SalesInvoiceReport.SetFilt("No."); DyconTimerReport.SetFilt("Bill-to Customer No.", '01' + COPYSTR(FORMAT(TODAY), 3, STRLEN(FORMAT(TODAY))) + '..' + FORMAT(tempDate)); DyconUtgiftReport.SetFilt("Bill-to Customer No.", '01' + COPYSTR(FORMAT(TODAY), 3, STRLEN(FORMAT(TODAY))) + '..' + FORMAT(tempDate)); Filenames[1] := 'C:\Temp\1.pdf'; Filenames[2] := 'C:\Temp\2.pdf'; Filenames[3] := 'C:\Temp\3.pdf'; SalesInvoiceReport.SAVEASPDF(Filenames[1]); DyconTimerReport.SAVEASPDF(Filenames[2]); DyconUtgiftReport.SAVEASPDF(Filenames[3]); IF ISCLEAR(DyconPDFMerger) THEN CREATE(DyconPDFMerger, FALSE, FALSE); tempText := DyconPDFMerger.MergeFiles('C:\Temp\output.pdf', 'C:\Temp\', '1.pdf;2.pdf;3.pdf');
Comments
1. Remove previous automation server
2. Release as x86 (Since NAS and Client uses x86)
3. Restart NAS
4. Register New automation server
5. Insert into code.
6. Create the automation server using this command