/// <summary> /// Tests the code128 C. /// </summary> /// <externalUnit/> /// <revision revisor="dev13" date="11/19/2009" version="1.1.3.7"> /// Added documentation header /// </revision> private static void TestCode128C() { string text = "98723493871103000000"; Bitmap barcode = Code128.Encode(text, 1, 0.125F, 96, 12, 0); PixelChar.DrawChar(barcode, 'M', 0, 2); Bitmap pixelchar = new Bitmap(70, 40); Graphics g = Graphics.FromImage(pixelchar); g.Clear(Color.White); g.Dispose(); pixelchar.SetResolution(96, 96); for (int i = 0; i < 7; i++) { for (int j = 0; j < 4; j++) { if (j * 7 + i < 26) { char ch = (char)(j * 7 + i + 65); PixelChar.DrawChar(pixelchar, ch, 10 * i, 10 * j); } } } MemoryInputStream misStream = new MemoryInputStream(barcode, 100); barcode.Dispose(); barcode.Dispose(); DSxInput pdfInput = new DSxInput(misStream); DSxSystem.setLicenseKey( "[Insert your license key here]"); DSxTask task = new DSxTask(); PDFxDocument pdfDoc = PDF.createDocument(task); PDFxContext context = pdfDoc.getContext(); PDFxPage pdfPage = pdfDoc.createCustomPage(5, 2); PDFxImage bar = PDFxImage.createImageFromJPEG(pdfInput); double dpi = 96D, k = 72D / dpi; pdfPage.drawImage( 18, 18, k * bar.getWidth(), k * bar.getHeight(), bar); bar = PDFxImage.createImageFromJPEG( new DSxInput(new MemoryInputStream(pixelchar, 100))); pixelchar.Dispose(); pdfPage.drawImage( 18, 72, k * bar.getWidth(), k * bar.getHeight(), bar); DSxPDFDocument dsDocument = new DSxPDFDocument(pdfDoc); dsDocument.save(new DSxOutput(@"bin\Debug\DSxInput2.pdf")); }
/// <summary> /// Extracts the pages as separate files. /// </summary> /// <param name="pdfDoc">The PDF doc.</param> /// <param name="strDestinationFolder"> /// The STR destination folder. /// </param> /// <param name="strFilename">The STR filename.</param> /// <exception cref="PdfIOException"> /// Unable to write to a specified PDF path/filename. /// </exception> /// <externalUnit/> /// <revision revisor="dev11" date="12/22/2008" version="1.0.0.0"> /// Member Created /// </revision> public static void ExtractPagesAsSeparateFiles( PDFxDocument pdfDoc, string strDestinationFolder, string strFilename) { int[] pages = new int[pdfDoc.getPageCount()]; for (int i = 0; i < pages.Length; i = i + 1) { pages[i] = i; } ExtractPagesAsSeparateFiles( pdfDoc, strDestinationFolder, strFilename, pages); }
/// <summary> /// Extracts the specified pages as separate files. /// </summary> /// <param name="pdfDoc">The PDF doc.</param> /// <param name="strDestinationFolder"> /// The STR destination folder. /// </param> /// <param name="strFilename">The STR filename.</param> /// <param name="pages">The pages (0-based).</param> /// <exception cref="PdfIOException"> /// Unable to write to a specified PDF path/filename. /// </exception> /// <externalUnit/> /// <revision revisor="dev11" date="2/25/2009" version="1.0.8.0801"> /// Member Created /// </revision> public static void ExtractPagesAsSeparateFiles( PDFxDocument pdfDoc, string strDestinationFolder, string strFilename, int[] pages) { if (Directory.Exists(strDestinationFolder) == false) { // if folder doesn't exist, create it Directory.CreateDirectory(strDestinationFolder); } if (strDestinationFolder.EndsWith(@"\") == false) { strDestinationFolder = strDestinationFolder + @"\"; } // create a task for this procedure DSxTask task = new DSxTask(); // in order to save the file, a document wrapper is needed DSxPDFDocument dsDocument = new DSxPDFDocument(pdfDoc); // save the file to a memory stream ByteArrayOutputStream os = new ByteArrayOutputStream(); DSxTDFDocument.save(dsDocument, new DSxOutput(os)); dsDocument.close(); try { string[] filenames = CreatePdfFilenames( // the number of pages is the page number of the last page // plus 1 since page indices are 0-based strFilename, pages[pages.Length - 1] + 1); for (int i = 0; i < pages.Length; i++) { dsDocument = DSxTDFDocument.getPDF( task, new DSxInput( new ByteArrayInputStream(os.toByteArray()))); dsDocument.extractPages(new int[] { pages[i] }); dsDocument.save( new DSxOutput( Path.Combine( // i.e.: // pages = {0, 2, 5} // // the page number of the last page is 5, so // filenames for pages 0-5 have to be generated // (6 pages total) // // filenames = { [filename 0], [filename 1], // [filename 2], [filename 3], [filename 4], // [filename 5] } strDestinationFolder, filenames[pages[i]]))); // close the document dsDocument.close(); } } catch (DSxRuntimeException) { throw new PdfIOException(); } finally { // close the document dsDocument.close(); // close the task task.close(); } }