/// <summary> /// The method renders the specified page's layers to a System.Drawing.Bitmap. /// </summary> /// <param name="doc">Document whose layers should be rendered</param> /// <param name="pg">page to render</param> /// <param name="parms">the DrawParams object</param> static void DrawLayersToGraphics(Document doc, Page pg, DrawParams parms) { IList <OptionalContentGroup> ocgs = doc.OptionalContentGroups; if (ocgs.Count > 0) { List <bool> states = new List <bool>(new bool[ocgs.Count]); for (int i = 0; i < ocgs.Count; ++i) { states[i] = true; using (OptionalContentContext occ = new OptionalContentContext(doc)) { // Render and save current layer occ.SetOCGStates(ocgs, states); parms.OptionalContentContext = occ; DrawLayerToGraphics(pg, parms, ocgs[i].Name); // return DrawParams to its initial value parms.OptionalContentContext = null; } states[i] = false; } } }
static void Main(string[] args) { Console.WriteLine("ListLayers Sample:"); // ReSharper disable once UnusedVariable using (Library lib = new Library()) { Console.WriteLine("Initialized the library."); String sInput = Library.ResourceDirectory + "Sample_Input/Layers.pdf"; if (args.Length > 0) { sInput = args[0]; } Console.WriteLine("Input file: " + sInput); Document doc = new Document(sInput); IList <OptionalContentGroup> ocgs = doc.OptionalContentGroups; foreach (OptionalContentGroup ocg in ocgs) { Console.WriteLine(ocg.Name); Console.Write(" Intent: ["); if (ocg.Intent.Count > 0) { IEnumerator <String> i = ocg.Intent.GetEnumerator(); i.MoveNext(); Console.Write(i.Current); while (i.MoveNext()) { Console.Write(", "); Console.Write(i.Current); } } Console.WriteLine("]"); } OptionalContentContext ctx = doc.OptionalContentContext; Console.Write("Optional content states: ["); IList <bool> states = ctx.GetOCGStates(ocgs); if (states.Count > 0) { IEnumerator <bool> i = states.GetEnumerator(); i.MoveNext(); Console.Write(i.Current); while (i.MoveNext()) { Console.Write(", "); Console.Write(i.Current); } } Console.WriteLine("]"); } }
public void CreateLayerItems(Document doc) { DestroyLayers(); if (doc == null) { layersInDocument = new List <LayerItems>(); return; } int controlHeight = 0; docLayerContext = new OptionalContentContext(doc); docLayers = doc.OptionalContentGroups; ocgStates = docLayerContext.GetOCGStates(docLayers); if (docLayers.Count > 1) { // create the master layer control, turns on/off all layers masterLayer = new LayerItems(this.Width); masterLayer.layerName.Text = "All Layers"; masterLayer.Location = new System.Drawing.Point(0, controlHeight); masterLayer.displayLayer.Name = "Master"; masterLayer.printLayer.Name = "Master"; // add the events for when the checkboxes are clicked masterLayer.displayLayer.Click += new EventHandler(dleController.displayLayer_Click); masterLayer.printLayer.Click += new EventHandler(dleController.printLayer_Click); // increase the height (y coordinate) so we do not overlap controls controlHeight += 65; // add the controls we just created to the layer manager this.Controls.Add(masterLayer); } layersInDocument = new List <LayerItems>(docLayers.Count); // create the layer items for all of the other layers that exist for (int i = 0; i < docLayers.Count; i++) { layersInDocument.Insert(i, new LayerItems(this.Width)); layersInDocument[i].layerName.Text = doc.OptionalContentGroups[i].Name; layersInDocument[i].Location = new System.Drawing.Point(0, controlHeight); // add the events for when the checkboxes are clicked layersInDocument[i].displayLayer.Click += new EventHandler(dleController.displayLayer_Click); layersInDocument[i].printLayer.Click += new EventHandler(dleController.printLayer_Click); controlHeight += 65; } foreach (LayerItems l in layersInDocument) { this.Controls.Add(l); } this.Invalidate(); }
public void Load(Document doc, Page page, Datalogics.PDFL.Point scale, OptionalContentContext occ) { Clear(); SetPageParam(doc, page, scale, occ); Tile fullPage = Create(CropRect); if (fullPage.IsValid) { fullBitmap = fullPage.TileBitmap; } else { tiles[0, 0] = Create(tiles[0, 0].TileRect); } }
/** * destroyLayers - * * Remove the controls for each layer and clear the list of * layers. Used when we open a new document. */ public void DestroyLayers() { docLayers = null; docLayerContext = null; ocgStates = null; if (layersInDocument != null) { // remove the control for each layer foreach (LayerItems l in layersInDocument) { this.Controls.Remove(l); } layersInDocument.Clear(); layersInDocument = null; // remove the master control also if (masterLayer != null) { this.Controls.Remove(masterLayer); } } }
public void SetPageParam(Document doc, Page page, Datalogics.PDFL.Point scale, OptionalContentContext occ) { this.scale = scale; //this.page = page; this.doc = doc; this.pageNum = page.PageNumber; this.occ = occ; SetPageRotate(page.Rotation); Rect cropBoxScaled = TransformRectByPageParam(page.CropBox, scale); cropRect = new Rectangle(); cropRect.Width = (int)cropBoxScaled.Width; cropRect.Height = (int)cropBoxScaled.Height; TileSize = new Size(1600, 1600); CreatePageTiles(); }