PDF Xpress for .NET - User Guide > How To > Save PDF as PDF/A-1b |
PDF Xpress™ supports saving a PDF document in PDF/A-1b format.
To save a PDF as PDF/A-1b:
PDF Xpress page render methods render uncompressed images. For optimal file size, we recommend using ImagXpress® to compress the rendered page image. |
C# Example |
Copy Code
|
---|---|
//This method will demonstrate how to use PDF Xpress to save a PDF document as a PDF/A-1b //compliant PDF. //sourceDoc - the Document object for the source "regular" PDF document. //targetDoc - the new Document we will form with the image of the regular PDF //and then save as PDF/A-1b. //iccProfileName - the path to a valid ICC profile. //imageXObject - ImagXpress object, to be used to compress the page image. //saveOptions - compression settings to compress the page image. private void saveAsPDFa1b(Document sourceDoc, Document targetDoc, String iccProfileFileName, ImagXpress imageXObject, Accusoft.ImagXpressSdk.SaveOptions saveOptions) { //render each page in the source PDF for (int page = 0; page < sourceDoc.PageCount; page++) { //RenderOptions for source PDF page RenderOptions sourceRenderOptions = new RenderOptions(); sourceRenderOptions.RenderAnnotations = false; sourceRenderOptions.ProduceDibSection = false; sourceRenderOptions.ResolutionX = 100; sourceRenderOptions.ResolutionY = 100; //render the original PDF page to an uncompressed Bitmap using(Bitmap pageBMP = sourceDoc.RenderPageToBitmap(page, sourceRenderOptions)) { //NOTE: For optimal file size, compress the Bitmap with ImagXpress 9 using (ImageX compressImage = ImageX.FromBitmap(imageXObject, pageBMP)) { using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { compressImage.SaveStream(ms, saveOptions); ms.Seek(0, System.IO.SeekOrigin.Begin); //create a new page in the new Document to be saved as PDF/A-1b PageOptions targetPageOpts = new PageOptions(); targetPageOpts.MediaHeight = (compressImage.ImageXData.Height / compressImage.ImageXData.Resolution.Dimensions.Width) * 72.0; targetPageOpts.MediaWidth = (compressImage.ImageXData.Width / compressImage.ImageXData.Resolution.Dimensions.Height) * 72.0; targetDoc.CreatePage(page - 1, targetPageOpts); //add the image of the original PDF page to the Document to be //saved as PDF/A-1b targetDoc.AddImage(page, 0, 0, targetPageOpts.MediaWidth, targetPageOpts.MediaHeight, ImageFitSettings.None, ms.ToArray(), 0); } } } } //specify conversion options //specify a valid ICC profile to embed ConvertOptions pdfaConvertOptions = new ConvertOptions(); pdfaConvertOptions.IccProfileFilename = iccProfileFileName; pdfaConvertOptions.PdfType = Accusoft.PdfXpressSdk.PdfType.pdfA1b; try { //convert the target Document to PDF/A-1b targetDoc.ConvertToPdfA(pdfaConvertOptions); } catch (Accusoft.PdfXpressSdk.PdfXpressException pdfException) { //a conversion problem was encountered } //save the new converted PDF/A-1b document Accusoft.PdfXpressSdk.SaveOptions targetSaveOptions = new Accusoft.PdfXpressSdk.SaveOptions(); targetSaveOptions.Filename = "convertedPDFaSampleDoc.pdf"; targetDoc.Save(targetSaveOptions); } } |