public PdfPage( PdfResources resources, PdfContentStream contents, int pagewidth, int pageheight, PdfObjectId objectId) : base(objectId) { this[PdfName.Names.Type] = PdfName.Names.Page; this[PdfName.Names.Resources] = resources.GetReference(); this[PdfName.Names.Contents] = contents.GetReference(); PdfArray mediaBox = new PdfArray(); mediaBox.Add(new PdfNumeric(0)); mediaBox.Add(new PdfNumeric(0)); mediaBox.Add(new PdfNumeric(pagewidth)); mediaBox.Add(new PdfNumeric(pageheight)); this[PdfName.Names.MediaBox] = mediaBox; }
public virtual void CheckPatternWithFormResourceCycle() { using (MemoryStream bos = new MemoryStream()) { using (PdfWriter writer = new PdfWriter(bos)) { using (PdfDocument document = new PdfDocument(writer)) { PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f)); formXObject.GetResources().AddForm(formXObject); PdfPattern.Tiling tillingPattern = new PdfPattern.Tiling(0f, 0f); tillingPattern.GetResources().AddForm(formXObject); PdfPage pageToCheck = document.AddNewPage(); PdfResources pageResources = pageToCheck.GetResources(); pageResources.AddPattern(new PdfPattern.Shading(new PdfDictionary())); pageResources.AddPattern(tillingPattern); EnsureTransparencyObjectsNotEmpty(); // no assertions as we want to check that no exceptions would be thrown pdfA2Checker.CheckSinglePage(pageToCheck); } } } }
public void StopRenderer() { fontSetup.AddToResources(new PdfFontCreator(pdfDoc), pdfDoc.getResources()); pdfDoc.outputTrailer(); pdfDoc = null; pdfResources = null; currentStream = null; currentAnnotList = null; currentPage = null; idReferences = null; currentFontName = String.Empty; currentFill = null; prevUnderlineColor = null; prevOverlineColor = null; prevLineThroughColor = null; fontSetup = null; fontInfo = null; }
/// <summary> /// Init /// </summary> public void Init(PdfResources resourcesDict) { extendedGStates = new Dictionary <string, List <State> >(); if (resourcesDict == null) { return; } var extGStatesDict = resourcesDict.ExtGStates; if (extGStatesDict == null) { return; } foreach (var element in extGStatesDict.Elements.Keys) { var settingsDict = extGStatesDict.Elements.GetDictionary(element); extendedGStates[element] = ReadExtendedState(settingsDict); } }
/// <summary> /// Init /// Note: Compared to the ExtGStates we cannot precompile the XObjects /// to GraphicPaths. Just because the result depends on the settings /// where the XObjects are used. The coordinates and the transparency /// of the parent influence the resulting coordinates and transparencies. /// </summary> public void Init(PdfResources resourcesDict) { xObjects = new Dictionary <string, PdfDictionary>(); if (resourcesDict == null) { return; } var xObjectsDict = resourcesDict.XObjects; if (xObjectsDict == null) { return; } foreach (var name in xObjectsDict.Elements.Keys) { var xObjectDict = xObjectsDict.Elements.GetDictionary(name); xObjects.Add(name, xObjectDict); } }
public virtual void CheckPatternWithTransparentFormResource() { using (MemoryStream bos = new MemoryStream()) { using (PdfWriter writer = new PdfWriter(bos)) { using (PdfDocument document = new PdfDocument(writer)) { PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f)); formXObject.SetGroup(new PdfTransparencyGroup()); PdfPattern.Tiling tillingPattern = new PdfPattern.Tiling(0f, 0f); tillingPattern.GetResources().AddForm(formXObject); PdfPage pageToCheck = document.AddNewPage(); PdfResources pageResources = pageToCheck.GetResources(); pageResources.AddPattern(new PdfPattern.Shading(new PdfDictionary())); pageResources.AddPattern(tillingPattern); NUnit.Framework.Assert.That(() => { pdfA2Checker.CheckSinglePage(pageToCheck); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_BUT_PAGE_CONTAINS_TRANSPARENCY_AND_DOES_NOT_CONTAIN_BLENDING_COLOR_SPACE)) ; } } } }
/// <summary> /// Init /// </summary> public void Init(PdfResources resourcesDict) { colorSpaces = new Dictionary <string, IColorSpace>(); IColorSpace predefinedColorSpace = new RGBDeviceColorSpace(); colorSpaces.Add(PdfKeys.DeviceRGB, predefinedColorSpace); predefinedColorSpace = new CMYKDeviceColorSpace(); colorSpaces.Add(PdfKeys.DeviceCMYK, predefinedColorSpace); predefinedColorSpace = new GrayDeviceColorSpace(); colorSpaces.Add(PdfKeys.DeviceGray, predefinedColorSpace); var predefinedColorSpacePattern = new PatternColorSpace(patternManager); colorSpaces.Add(PdfKeys.DevicePattern, predefinedColorSpacePattern); if (resourcesDict != null) { ReadResourceDefinedColorSpaces(resourcesDict); } }
public virtual void ModifyAxialShadingTest() { String testName = "modifyAxialShadingTest"; String outName = destinationFolder + testName + ".pdf"; String cmpName = sourceFolder + "cmp_" + testName + ".pdf"; String input = sourceFolder + "axialShading.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(input), new PdfWriter(outName), new StampingProperties ().UseAppendMode()); PdfResources resources = pdfDocument.GetPage(1).GetResources(); foreach (PdfName resName in resources.GetResourceNames()) { PdfShading shading = resources.GetShading(resName); if (shading != null && shading.GetShadingType() == PdfShading.ShadingType.AXIAL) { PdfShading.Axial axialShading = (PdfShading.Axial)shading; // "cut" shading and extend colors axialShading.SetDomain(0.1f, 0.8f); axialShading.SetExtend(true, true); } } pdfDocument.Close(); AssertShadingDictionaryResult(outName, cmpName, "Sh1"); }
public virtual void InnerArraysInContentStreamTest() { String inputFileName = sourceFolder + "innerArraysInContentStream.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inputFileName)); byte[] docInBytes = pdfDocument.GetFirstPage().GetContentBytes(); RandomAccessSourceFactory factory = new RandomAccessSourceFactory(); PdfTokenizer tokeniser = new PdfTokenizer(new RandomAccessFileOrArray(factory.CreateSource(docInBytes))); PdfResources resources = pdfDocument.GetPage(1).GetResources(); PdfCanvasParser ps = new PdfCanvasParser(tokeniser, resources); IList <PdfObject> actual = ps.Parse(null); IList <PdfObject> expected = new List <PdfObject>(); expected.Add(new PdfString("Cyan")); expected.Add(new PdfArray(new int[] { 1, 0, 0, 0 })); expected.Add(new PdfString("Magenta")); expected.Add(new PdfArray(new int[] { 0, 1, 0, 0 })); expected.Add(new PdfString("Yellow")); expected.Add(new PdfArray(new int[] { 0, 0, 1, 0 })); PdfArray cmpArray = new PdfArray(expected); NUnit.Framework.Assert.IsTrue(new CompareTool().CompareArrays(cmpArray, (((PdfDictionary)actual[1]).GetAsArray (new PdfName("ColorantsDef"))))); }
/// <summary> /// Init /// </summary> public void Init(PdfResources resourcesDict) { shadings = new Dictionary <string, IShading>(); if (resourcesDict == null) { return; } var shadingsDict = resourcesDict.Shadings; if (shadingsDict == null) { return; } foreach (var name in shadingsDict.Elements.Keys) { var shadingDict = shadingsDict.Elements.GetDictionary(name); var fd = ReadShading(shadingDict); shadings.Add(name, fd); } }
public override void CheckIsoConformance(Object obj, IsoKey key, PdfResources resources, PdfStream contentStream ) { CanvasGraphicsState gState; PdfDictionary currentColorSpaces = null; if (resources != null) { currentColorSpaces = resources.GetPdfObject().GetAsDictionary(PdfName.ColorSpace); } switch (key) { case IsoKey.CANVAS_STACK: { checker.CheckCanvasStack((char)obj); break; } case IsoKey.PDF_OBJECT: { checker.CheckPdfObject((PdfObject)obj); break; } case IsoKey.RENDERING_INTENT: { checker.CheckRenderingIntent((PdfName)obj); break; } case IsoKey.INLINE_IMAGE: { checker.CheckInlineImage((PdfStream)obj, currentColorSpaces); break; } case IsoKey.EXTENDED_GRAPHICS_STATE: { gState = (CanvasGraphicsState)obj; checker.CheckExtGState(gState, contentStream); break; } case IsoKey.FILL_COLOR: { gState = (CanvasGraphicsState)obj; checker.CheckColor(gState.GetFillColor(), currentColorSpaces, true, contentStream); break; } case IsoKey.PAGE: { checker.CheckSinglePage((PdfPage)obj); break; } case IsoKey.STROKE_COLOR: { gState = (CanvasGraphicsState)obj; checker.CheckColor(gState.GetStrokeColor(), currentColorSpaces, false, contentStream); break; } case IsoKey.TAG_STRUCTURE_ELEMENT: { checker.CheckTagStructureElement((PdfObject)obj); break; } case IsoKey.FONT_GLYPHS: { checker.CheckFontGlyphs(((CanvasGraphicsState)obj).GetFont(), contentStream); break; } } }
public override void CheckIsoConformance(Object obj, IsoKey key, PdfResources resources) { CheckIsoConformance(obj, key, resources, null); }
public override void Flush() { resources = null; base.Flush(); }
public _PdfCanvas_164(LinkedList <CanvasTag> tags, PdfStream baseArg1, PdfResources baseArg2, PdfDocument baseArg3 ) : base(baseArg1, baseArg2, baseArg3) { this.tags = tags; this.tagsToCompare = tags; }
/// <summary>Creates a new instance of PdfContentParser</summary> /// <param name="tokeniser">the tokeniser with the content</param> /// <param name="currentResources"> /// current resources of the content stream. /// It is optional parameter, which is used for performance improvements of specific cases of /// inline images parsing. /// </param> public PdfCanvasParser(PdfTokenizer tokeniser, PdfResources currentResources) { this.tokeniser = tokeniser; this.currentResources = currentResources; }
public override void CheckIsoConformance(Object obj, IsoKey key, PdfResources resources) { CanvasGraphicsState gState; PdfDictionary currentColorSpaces = null; if (resources != null) { currentColorSpaces = resources.GetPdfObject().GetAsDictionary(PdfName.ColorSpace); } switch (key) { case IsoKey.CANVAS_STACK: { checker.CheckCanvasStack((char)obj); break; } case IsoKey.PDF_OBJECT: { checker.CheckPdfObject((PdfObject)obj); break; } case IsoKey.RENDERING_INTENT: { checker.CheckRenderingIntent((PdfName)obj); break; } case IsoKey.INLINE_IMAGE: { checker.CheckInlineImage((PdfStream)obj, currentColorSpaces); break; } case IsoKey.GRAPHIC_STATE_ONLY: { gState = (CanvasGraphicsState)obj; checker.CheckExtGState(gState); break; } case IsoKey.DRAWMODE_FILL: { gState = (CanvasGraphicsState)obj; checker.CheckColor(gState.GetFillColor(), currentColorSpaces, true); checker.CheckExtGState(gState); break; } case IsoKey.DRAWMODE_STROKE: { gState = (CanvasGraphicsState)obj; checker.CheckColor(gState.GetStrokeColor(), currentColorSpaces, false); checker.CheckExtGState(gState); break; } case IsoKey.DRAWMODE_FILL_STROKE: { gState = (CanvasGraphicsState)obj; checker.CheckColor(gState.GetFillColor(), currentColorSpaces, true); checker.CheckColor(gState.GetStrokeColor(), currentColorSpaces, false); checker.CheckExtGState(gState); break; } case IsoKey.PAGE: { checker.CheckSinglePage((PdfPage)obj); break; } } }
public CanvasGraphicsStateSettablePdfCanvas(PdfStream contentStream, PdfResources resources, PdfDocument document) : base(contentStream, resources, document) { }
/// <summary>Creates PdfPatternCanvas from content stream of page, form XObject, pattern etc.</summary> /// <param name="contentStream">The content stream</param> /// <param name="resources">The resources, a specialized dictionary that can be used by PDF instructions in the content stream /// </param> /// <param name="document">The document that the resulting content stream will be written to</param> public PdfPatternCanvas(PdfStream contentStream, PdfResources resources, PdfDocument document) : base(contentStream, resources, document) { this.tilingPattern = new PdfPattern.Tiling(contentStream); }
private IDictionary <int, CleanUpImagesCompareTool.PageImageObjectsPaths> ExtractImagesFromPdf(String pdf, String outputPath) { using (PdfReader readerPdf = new PdfReader(pdf)) { using (PdfDocument pdfDoc = new PdfDocument(readerPdf)) { IDictionary <int, CleanUpImagesCompareTool.PageImageObjectsPaths> imageObjectDatas = new Dictionary <int, CleanUpImagesCompareTool.PageImageObjectsPaths >(); for (int i = 1; i <= pdfDoc.GetNumberOfPages(); i++) { PdfPage page = pdfDoc.GetPage(i); CleanUpImagesCompareTool.PageImageObjectsPaths imageObjectData = new CleanUpImagesCompareTool.PageImageObjectsPaths (page.GetPdfObject().GetIndirectReference()); Stack <LocalPathItem> baseLocalPath = new Stack <LocalPathItem>(); PdfResources pdfResources = page.GetResources(); if (pdfResources.GetPdfObject().IsIndirect()) { imageObjectData.AddIndirectReference(pdfResources.GetPdfObject().GetIndirectReference()); } else { baseLocalPath.Push(new DictPathItem(PdfName.Resources)); } PdfDictionary xObjects = pdfResources.GetResource(PdfName.XObject); if (xObjects == null) { continue; } if (xObjects.IsIndirect()) { imageObjectData.AddIndirectReference(xObjects.GetIndirectReference()); baseLocalPath.Clear(); } else { baseLocalPath.Push(new DictPathItem(PdfName.XObject)); } bool isPageToGsExtract = false; foreach (PdfName objectName in xObjects.KeySet()) { if (!xObjects.Get(objectName).IsStream() || !PdfName.Image.Equals(xObjects.GetAsStream(objectName).GetAsName (PdfName.Subtype))) { continue; } PdfImageXObject pdfObject = new PdfImageXObject(xObjects.GetAsStream(objectName)); baseLocalPath.Push(new DictPathItem(objectName)); if (!useGs) { String extension = pdfObject.IdentifyImageFileExtension(); String fileName = outputPath + objectName + "_" + i + "." + extension; CreateImageFromPdfXObject(fileName, pdfObject); } else { isPageToGsExtract = true; } Stack <LocalPathItem> reversedStack = new Stack <LocalPathItem>(); reversedStack.AddAll(baseLocalPath); Stack <LocalPathItem> resultStack = new Stack <LocalPathItem>(); resultStack.AddAll(reversedStack); imageObjectData.AddLocalPath(resultStack); baseLocalPath.Pop(); } if (useGs && isPageToGsExtract) { String fileName = "Page_" + i; ghostscriptHelper.RunGhostScriptImageGeneration(pdf, outputPath, fileName, i.ToString()); } CleanUpImagesCompareTool.ImageRenderListener listener = new CleanUpImagesCompareTool.ImageRenderListener(); PdfCanvasProcessor parser = new PdfCanvasProcessor(listener); parser.ProcessPageContent(page); ignoredImagesAreas.Put(i, listener.GetImageRectangles()); imageObjectDatas.Put(i, imageObjectData); } return(imageObjectDatas); } } }