static void Main(string[] args)
        {
            Console.WriteLine("ZUGFeRDConverter Sample:");

            //Initialize the Library
            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                if (args.Length < 2)
                {
                    Console.WriteLine("You must specify an input PDF and an input ZUGFeRD Invoice XML file, e.g.:");
                    Console.WriteLine();
                    Console.WriteLine("ConvertToZUGFeRD input-file.pdf input-ZUGFeRD-invoice.xml");

                    return;
                }

                String sInputPDF        = args[0];
                String sInputInoviceXML = args[1];
                String sOutput          = "../ZUGFeRDConverter-out.pdf";

                Console.WriteLine("Converting " + sInputPDF + " with " + sInputInoviceXML + ", output file is " + sOutput);

                // Step 1) Open the input PDF
                using (Document doc = new Document(sInputPDF))
                {
                    // Step 2) Open the input Invoice XML and attach it to the PDF
                    using (FileAttachment attachment = new FileAttachment(doc, sInputInoviceXML))
                    {
                        // Make a conversion parameters object
                        PDFAConvertParams pdfaParams = new PDFAConvertParams();
                        pdfaParams.IgnoreFontErrors   = false;
                        pdfaParams.NoValidationErrors = false;
                        pdfaParams.ValidateImplementationLimitsOfDocument = true;

                        // Step 3) Convert the input PDF to be a PDF/A-3 document.
                        PDFAConvertResult pdfaResult = doc.CloneAsPDFADocument(PDFAConvertType.RGB3b, pdfaParams);

                        // The conversion may have failed: we must check if the result has a valid Document
                        if (pdfaResult.PDFADocument == null)
                        {
                            Console.WriteLine("ERROR: Could not convert " + sInputPDF + " to PDF/A.");
                        }
                        else
                        {
                            Console.WriteLine("Successfully converted " + sInputPDF + " to PDF/A.");

                            Document pdfaDoc = pdfaResult.PDFADocument;

                            //Step 4) Add the required XMP metadata entries
                            AddMetadataAndExtensionSchema(pdfaDoc, sInputInoviceXML);

                            //Step 5) Save the document
                            pdfaDoc.Save(pdfaResult.PDFASaveFlags, sOutput);
                        }
                    }
                }
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("PDFAConverter Sample:");

            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                String sInput  = "../../Resources/Sample_Input/ducky.pdf";
                String sOutput = "../PDFAConverter-out.pdf";

                if (args.Length > 0)
                {
                    sInput = args[0];
                }

                if (args.Length > 1)
                {
                    sOutput = args[1];
                }

                Console.WriteLine("Converting " + sInput + ", output file is " + sOutput);

                Document doc = new Document(sInput);

                // Make a conversion parameters object
                PDFAConvertParams pdfaParams = new PDFAConvertParams();

                // We'll set a property on it an as example
                pdfaParams.AbortIfXFAIsPresent = true;

                // Create a PDF/A compliant version of the document
                //   (Or use convert type PDFAConvertType.CMYK1b)
                PDFAConvertResult pdfaResult = doc.CloneAsPDFADocument(PDFAConvertType.RGB1b, pdfaParams);

                // The conversion may have failed: we must check if the result has a valid Document
                if (pdfaResult.PDFADocument == null)
                {
                    Console.WriteLine("ERROR: Could not convert " + sInput + " to PDF/A.");
                }
                else
                {
                    Console.WriteLine("Successfully converted " + sInput + " to PDF/A.");

                    Document pdfaDoc = pdfaResult.PDFADocument;

                    // We MUST use the SaveFlags returned in the PDFConvertResult.
                    // If we do not use them, the document will no longer be PDF/A compliant.
                    pdfaDoc.Save(pdfaResult.PDFASaveFlags, sOutput);

                    // Note that the returned document will have its major and minor
                    // version set--this is required for PDF/A compliance.  This is only
                    // visible AFTER you save the document.
                    Console.WriteLine(sOutput + " has version number: " + pdfaDoc.MajorVersion + "." + pdfaDoc.MinorVersion);
                }
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("PDFAConverter Sample:");

            // ReSharper disable once UnusedVariable
            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                String sInput  = Library.ResourceDirectory + "Sample_Input/ducky.pdf";
                String sOutput = "PDFAConverter-out.pdf";

                if (args.Length > 0)
                {
                    sInput = args[0];
                }

                if (args.Length > 1)
                {
                    sOutput = args[1];
                }

                Console.WriteLine("Converting " + sInput + ", output file is " + sOutput);

                using (Document doc = new Document(sInput))
                {
                    // Make a conversion parameters object
                    PDFAConvertParams pdfaParams = new PDFAConvertParams();
                    pdfaParams.AbortIfXFAIsPresent = true;
                    pdfaParams.IgnoreFontErrors    = false;
                    pdfaParams.NoValidationErrors  = false;
                    pdfaParams.ValidateImplementationLimitsOfDocument = true;

                    // Create a PDF/A compliant version of the document
                    PDFAConvertResult pdfaResult = doc.CloneAsPDFADocument(PDFAConvertType.RGB1b, pdfaParams);

                    // The conversion may have failed: we must check if the result has a valid Document
                    if (pdfaResult.PDFADocument == null)
                    {
                        Console.WriteLine("ERROR: Could not convert " + sInput + " to PDF/A.");
                    }
                    else
                    {
                        Console.WriteLine("Successfully converted " + sInput + " to PDF/A.");

                        Document pdfaDoc = pdfaResult.PDFADocument;

                        //Save the result.
                        pdfaDoc.Save(pdfaResult.PDFASaveFlags, sOutput);
                    }
                }
            }
        }