public override PDFGraphics CreateGraphics(PDFWriter writer, StyleStack styles, PDFContextBase context) { Style full = styles.GetFullStyle(this); PageSize size = this.GetPageSize(full); return(PDFGraphics.Create(writer, false, this, DrawingOrigin.TopLeft, size.Size, context)); }
/// <summary> /// Closes this instance. /// </summary> public void Close() { if (!CanModify) { throw new InvalidOperationException(PSSR.CannotModify); } if (OutStream != null) { // Get security handler if document gets encrypted PDFStandardSecurityHandler securityHandler = null; if (SecuritySettings.DocumentSecurityLevel != PDFDocumentSecurityLevel.None) { securityHandler = SecuritySettings.SecurityHandler; } PDFWriter writer = new PDFWriter(OutStream, securityHandler); try { DoSave(writer); } finally { writer.Close(); } } }
protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { PDFName name = PDFLayoutMarkedContentBegin.GetNameForContentType(this.Begin.ContentType); context.Graphics.EndMarkedContent(name); return(base.DoOutputToPDF(context, writer)); }
/// <summary> /// Outputs the first Page tree Component and calls Output on each of the layout pages. /// </summary> /// <param name="context">The current context</param> /// <param name="writer">The current writer</param> /// <returns>A reference to the current page tree root Component</returns> protected virtual PDFObjectRef OutputPageTree(PDFRenderContext context, PDFWriter writer) { //Begin the Pages object and dictionary PDFObjectRef pgs = writer.BeginObject(Const.PageTreeName); writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Type", "Pages"); List <PDFObjectRef> pagerefs = OutputAllPages(pgs, context, writer); //write the kids array entry in the dictionary writer.BeginDictionaryEntry("Kids"); writer.BeginArray(); foreach (PDFObjectRef kid in pagerefs) { writer.BeginArrayEntry(); writer.WriteFileObject(kid); writer.EndArrayEntry(); } writer.EndArray(); //Write the total number of pages to the dictionary writer.EndDictionaryEntry(); writer.BeginDictionaryEntry("Count"); writer.WriteNumber(pagerefs.Count); writer.EndDictionaryEntry(); //close the ditionary and the object writer.EndDictionary(); writer.EndObject(); return(pgs); }
/// <summary> /// If this document has artefacts then the collection is output. /// </summary> /// <param name="context"></param> /// <param name="writer"></param> private void WriteArtefacts(PDFRenderContext context, PDFWriter writer) { PDFArtefactCollectionSet artefacts = this.Artefacts; if (artefacts != null && artefacts.Count > 0) { foreach (IArtefactCollection col in artefacts) { context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Outputting artefact catalog entry collection " + col.CollectionName); writer.BeginDictionaryEntry(col.CollectionName); PDFObjectRef entry = col.OutputToPDF(context, writer); if (entry != null) { writer.WriteObjectRef(entry); } else { writer.WriteNull(); } writer.EndDictionaryEntry(); context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished artefact catalog entry collection " + col.CollectionName); } } }
public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { if (this.Fields.Count > 0) { PDFObjectRef parent = writer.BeginObject(); List <PDFObjectRef> children = new List <PDFObjectRef>(); foreach (var fld in this.Fields) { var child = fld.OutputToPDF(context, writer); if (null != child) { children.Add(child); } } writer.BeginDictionary(); writer.WriteDictionaryStringEntry("T", this.Name); writer.BeginDictionaryEntry("Kids"); writer.WriteArrayRefEntries(true, children.ToArray()); writer.EndDictionaryEntry(); writer.EndDictionary(); writer.EndObject(); return(parent); } return(null); }
public ActionResult Home() { var pdf = new PDFWriter(); pdf.Build("teste", "teste"); return(Redirect("/swagger/index.html")); }
// // methods // public virtual PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { if (this.IsEmpty()) { if (context.ShouldLogMessage) { context.TraceLog.Add(TraceLevel.Message, "Viewer Preferences", "No values set on the document viewer preferences so not outputting"); } return(null); } else { PDFObjectRef oref = writer.BeginObject(); writer.BeginDictionary(); this.WriteOptionalFlag("CenterWindow", _centrewindow, context, writer); this.WriteOptionalFlag("FitWindow", _fitwindow, context, writer); this.WriteOptionalFlag("HideWindowUI", _hidewindowui, context, writer); this.WriteOptionalFlag("HideToolbar", _hidetoolbar, context, writer); this.WriteOptionalFlag("HideMenubar", _hidemenubar, context, writer); if (this.NonFullScreenPageDisplay != PageDisplayMode.Undefined) { this.WriteOptionalName("NonFullScreenPageMode", this.NonFullScreenPageDisplay.ToString(), context, writer); } writer.EndDictionary(); writer.EndObject(); return(oref); } }
public void RenderOverLines(PDFTextRunEnd end, PDFRenderContext context, PDFWriter writer) { PDFUnit offsetV = new PDFUnit(-this.TextRenderOptions.GetAscent().PointsValue, PageUnits.Points); PDFUnit linethickness = this.TextRenderOptions.Font.Size / ThicknessFactor; this.RenderTextDecoration(end, context, writer, offsetV, linethickness); }
protected virtual void RenderImageInformation(PDFContextBase context, PDFWriter writer) { writer.WriteDictionaryNumberEntry("Width", this.PixelWidth); writer.WriteDictionaryNumberEntry("Height", this.PixelHeight); //writer.WriteDictionaryNumberEntry("Length", this.Data.LongLength); //- commented for data length fix if (this.ColorSpace == ColorSpace.G) { writer.WriteDictionaryNameEntry("ColorSpace", "DeviceGray"); } else if (this.ColorSpace == ColorSpace.Custom) { this.RenderCustomColorSpace(writer); } else if (this.ColorSpace == Drawing.ColorSpace.CMYK) { writer.WriteDictionaryNameEntry("ColorSpace", "DeviceCMYK"); } else { writer.WriteDictionaryNameEntry("ColorSpace", "DeviceRGB"); } WriteFilterNames(context, writer); writer.WriteDictionaryNumberEntry("BitsPerComponent", this.BitsPerColor); if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Image Data", "Rendered image information dictionary : cs=" + this.ColorSpace + ", w=" + this.PixelWidth + ", h=" + this.PixelHeight + ", bpc=" + BitsPerColor); } }
protected PDFGraphics(PDFWriter writer, PDFSize size, IPDFResourceContainer container) { this._writer = writer; this._pageSize = size; this._rsrc = container; this._extState = new PDFExternalGraphicsState(container, writer); }
public void RenderUnderlines(PDFTextRunEnd end, PDFRenderContext context, PDFWriter writer) { PDFUnit offsetV = this.TextRenderOptions.GetAscent() / UnderlineOffsetFactor; PDFUnit linethickness = this.TextRenderOptions.Font.Size / ThicknessFactor; this.RenderTextDecoration(end, context, writer, offsetV, linethickness); }
protected override void WriteCatalogEntries(PDFRenderContext context, PDFWriter writer) { if (null != this.OriginalFile) { PDFObjectRef catalog = writer.LastObjectReference(); PDFObjectRef pageTree = this.OutputPageTree(context, writer); foreach (KeyValuePair <PDFName, IFileObject> item in this.ExistingCatalog) { if (item.Key.Value == "Pages") { //PDFObjectRef pages = this.OutputAllPages writer.BeginDictionaryEntry(item.Key); pageTree.WriteData(writer); writer.EndDictionaryEntry(); } else { writer.BeginDictionaryEntry(item.Key); item.Value.WriteData(writer); writer.EndDictionaryEntry(); } } } else { base.WriteCatalogEntries(context, writer); } }
public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Verbose, "Annotation Collection", "Outputting the doument annotations to the writer"); } PDFObjectRef annot = writer.BeginObject(); List <PDFObjectRef> entries = new List <PDFObjectRef>(); //TODO:Render annotations foreach (PDFAnnotationEntry entry in this._annots) { PDFObjectRef oref = entry.OutputToPDF(context, writer); if (oref != null) { entries.Add(oref); } } writer.WriteArrayRefEntries(entries.ToArray()); writer.EndObject(); if (context.ShouldLogDebug) { context.TraceLog.End(TraceLevel.Verbose, "Annotation Collection", "Completed the output of " + entries.Count + " annotations on the writer"); } return(annot); }
/// <summary> /// Outputs the positioning and visibility of UI elements for the viewer /// </summary> /// <param name="context"></param> /// <param name="writer"></param> protected virtual void WriteViewerPreferences(PDFRenderContext context, PDFWriter writer) { DocumentViewPreferences docview = this.DocumentComponent.ViewPreferences; if (null != docview) { PDFObjectRef view = docview.OutputToPDF(context, writer); if (null != view) { writer.WriteDictionaryObjectRefEntry("ViewerPreferences", view); } string value = docview.GetPageDisplayName(docview.PageDisplay); if (!string.IsNullOrEmpty(value)) { writer.WriteDictionaryNameEntry("PageMode", value); } value = docview.GetPageLayoutName(docview.PageLayout); if (!string.IsNullOrEmpty(value)) { writer.WriteDictionaryNameEntry("PageLayout", value); } } }
// // rendering // protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { if (context.ShouldLogVerbose) { context.TraceLog.Begin(TraceLevel.Verbose, "Layout Page", "Starting the render of Page: " + this.PageIndex); } else if (context.ShouldLogMessage) { context.TraceLog.Add(TraceLevel.Message, "Layout Page", "Rendering layout page " + this.PageIndex); } //get the current style and aply it to the style stack Style style = this.FullStyle; context.StyleStack.Push(style); PageSize pagesize = this.PageOwner.GetPageSize(style); //PDFPageNumbering num = this.GetNumbering(style); //this.Document.RegisterPageNumbering(context.PageIndex, this, num); PDFObjectRef last = writer.LastObjectReference(); PDFObjectRef pg; pg = DoWritePage(context, writer, last); context.StyleStack.Pop(); if (context.ShouldLogVerbose) { context.TraceLog.End(TraceLevel.Verbose, "Layout Page", "Completed the rendering of page: " + this.PageIndex); } return(pg); }
protected void OutputInfoEntry(string name, string value, PDFWriter writer) { if (!string.IsNullOrEmpty(value)) { writer.WriteDictionaryStringEntry(name, value.Trim()); } }
public void CreateReportCard(string outFilename, MarkingPeriod period) { var currentSubjects = _student.Grades.GroupBy(g => g.Subject) .Where(subject => subject.Any(subGrade => subGrade.IsCurrentForPeriod(period.Key))) .OrderBy(subject => Maintenance.GetSubjectIndex(subject.Key)); var gradeReportFields = currentSubjects.Select((subject, i) => { var thisYearsGrades = subject.Where(subGrade => subGrade.ShouldShowOnReportCard(period)) .Select(subGrade => subGrade.GetGradeReportFields(period.Key, i + 1)); return(thisYearsGrades.SelectMany(x => x)); }).SelectMany(x => x); var outputProperties = gradeReportFields.Concat(GetPDFFields(this)) .Concat(GetReportLevelFields(period.Key)) .Concat(GetSelfDevFields(period.Key)); if (outFilename == null) { var tempDir = Path.GetTempPath(); Directory.CreateDirectory(tempDir); string tempFileName = Path.Combine(tempDir, GetDefaultReportCardFilename(period.Key) + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf"); PDFWriter.WritePDF(tempFileName, outputProperties.ToDictionary(p => p.Key, p => p.Value)); Process.Start(tempFileName); } else { PDFWriter.WritePDF(outFilename, outputProperties.ToDictionary(p => p.Key, p => p.Value)); } }
// // methods // #region public virtual PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) + Support methods /// <summary> /// Outputs this Info to the current writer /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> public virtual PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { PDFObjectRef inforef = writer.BeginObject("Info"); writer.BeginDictionary(); OutputInfoEntry("Title", this.Title, writer); OutputInfoEntry("Subject", this.Subject, writer); OutputInfoEntry("Author", this.Author, writer); OutputInfoEntry("Keywords", this.Keywords, writer); OutputInfoEntry("Producer", this.Producer, writer); OutputInfoEntry("Creator", this.Creator, writer); OutputInfoEntry("CreationDate", this.CreationDate, writer); OutputInfoEntry("ModDate", this.ModifiedDate, writer); if (this.HasTrapping) { writer.WriteDictionaryNameEntry("Trapped", this.Trapped.ToString()); } if (this.HasExtras) { foreach (PDFDocumentInfoExtra extra in this.Extras) { OutputInfoEntry(extra.Name, extra.Value, writer); } } writer.EndDictionary(); writer.EndObject(); return(inforef); }
public PDFExternalGraphicsState(IPDFResourceContainer container, PDFWriter writer) { _states = new Stack <StateInfo>(); _identity = new StateInfo(1.0, 1.0); _container = container; _writer = writer; }
protected void DoWriteArtefacts(PDFRenderContext context, PDFWriter writer) { if (this.Artefacts != null && this.Artefacts.Count > 0) { foreach (IArtefactCollection col in this.Artefacts) { if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Debug, "Layout Page", "Rendering artefact entry " + col.CollectionName); } PDFObjectRef artefact = col.OutputToPDF(context, writer); if (null != artefact) { writer.WriteDictionaryObjectRefEntry(col.CollectionName, artefact); } if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Debug, "Layout Page", "Finished artefact entry " + col.CollectionName); } } } }
protected virtual int RenderImageStreamData(PDFContextBase context, PDFWriter writer) { if (this.Data.LongLength > (long)int.MaxValue) { throw new ArgumentOutOfRangeException("This image is too large to be included in a PDF file"); } byte[] data = this.Data; if (this.ShouldApplyFilters(context)) { byte[] filtered; filtered = this.GetCachedFilteredData(this.Filters, context); if (null == filtered) { filtered = ApplyFiltersToData(data, context); this.SetCachedFilteredData(this.Filters, filtered, context); } data = filtered; } writer.WriteRaw(data, 0, data.Length); if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Image Data", "Written raw image data to output with length " + data.Length); } //Added for data length fix - HRB 15/01/2015 return(data.Length); //End of add }
protected virtual void WriteCatalogEntries(PDFRenderContext context, PDFWriter writer) { // Pages context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Starting to write Pages"); PDFObjectRef pglist = this.OutputPageTree(context, writer); writer.WriteDictionaryObjectRefEntry("Pages", pglist); context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished writing Pages with page tree " + pglist); // Page Labels context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Starting to write Page Labels"); PDFObjectRef pglabels = this.WritePageLabels(context, writer); if (null != pglabels) { writer.WriteDictionaryObjectRefEntry("PageLabels", pglabels); } context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished writing Page Labels"); // Artefacts context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Starting to write document Artefacts"); this.WriteArtefacts(context, writer); context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished writing document Artefacts"); //Viewer Preferences context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Starting to write Viewer Preferences"); this.WriteViewerPreferences(context, writer); context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished writing Viewer Preferences"); }
internal override void WriteObject(PDFWriter writer) { PDFPage dest = null; //pdf.AppendFormat(CultureInfo.InvariantCulture, // "{0} 0 obj\n<<\n/Type/Annot\n/Subtype/Link\n" + // "/Rect[{1} {2} {3} {4}]\n/BS<</Type/Border>>\n/Border[0 0 0]\n/C[0 0 0]\n", // ObjectID.ObjectNumber, rect.X1, rect.Y1, rect.X2, rect.Y2); // Older Adobe Reader versions uses a border width of 0 as default value if neither Border nor BS are present. // But the PDF Reference specifies: // "If neither the Border nor the BS entry is present, the border is drawn as a solid line with a width of 1 point." // After this issue was fixed in newer Reader versions older PDFSharp created documents show an ugly solid border. // The following hack fixes this by specifying a 0 width border. if (Elements[PDFAnnotation.Keys.BS] == null) { Elements[PDFAnnotation.Keys.BS] = new PDFLiteral("<</Type/Border/W 0>>"); } // May be superfluous. See comment above. if (Elements[PDFAnnotation.Keys.Border] == null) { Elements[PDFAnnotation.Keys.Border] = new PDFLiteral("[0 0 0]"); } switch (_linkType) { case LinkType.None: break; case LinkType.Document: // destIndex > Owner.PageCount can happen when rendering pages using PDFSharp directly. int destIndex = _destPage; if (destIndex > Owner.PageCount) { destIndex = Owner.PageCount; } destIndex--; dest = Owner.Pages[destIndex]; //pdf.AppendFormat("/Dest[{0} 0 R/XYZ null null 0]\n", dest.ObjectID); Elements[Keys.Dest] = new PDFLiteral("[{0} 0 R/XYZ null null 0]", dest.ObjectNumber); break; case LinkType.Web: //pdf.AppendFormat("/A<</S/URI/URI{0}>>\n", PDFEncoders.EncodeAsLiteral(url)); Elements[PDFAnnotation.Keys.A] = new PDFLiteral("<</S/URI/URI{0}>>", //PDFEncoders.EncodeAsLiteral(url)); PDFEncoders.ToStringLiteral(_url, PDFStringEncoding.WinAnsiEncoding, writer.SecurityHandler)); break; case LinkType.File: //pdf.AppendFormat("/A<</Type/Action/S/Launch/F<</Type/Filespec/F{0}>> >>\n", // PDFEncoders.EncodeAsLiteral(url)); Elements[PDFAnnotation.Keys.A] = new PDFLiteral("<</Type/Action/S/Launch/F<</Type/Filespec/F{0}>> >>", //PDFEncoders.EncodeAsLiteral(url)); PDFEncoders.ToStringLiteral(_url, PDFStringEncoding.WinAnsiEncoding, writer.SecurityHandler)); break; } base.WriteObject(writer); }
protected virtual PDFObjectRef DoWritePage(PDFRenderContext context, PDFWriter writer, PDFObjectRef parent) { PDFObjectRef pg = writer.BeginPage(context.PageIndex); this.PageObjectRef = pg; writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Type", "Page"); writer.WriteDictionaryObjectRefEntry("Parent", parent); writer.BeginDictionaryEntry("MediaBox"); writer.WriteArrayRealEntries(0.0, 0.0, this.Size.Width.ToPoints().Value, this.Size.Height.ToPoints().Value); writer.EndDictionaryEntry(); if (this.FullStyle.IsValueDefined(StyleKeys.PageAngle)) { int value = this.FullStyle.GetValue(StyleKeys.PageAngle, 0); writer.WriteDictionaryNumberEntry("Rotate", value); } context.PageSize = this.Size; context.Offset = new PDFPoint(); context.Space = context.PageSize; if (context.ShouldLogVerbose) { context.TraceLog.Add(TraceLevel.Verbose, "Layout Page", "Rendering the contents of page : " + this.PageIndex); } PDFObjectRef content = this.OutputContent(context, writer); if (content != null) { writer.WriteDictionaryObjectRefEntry("Contents", content); } if (context.ShouldLogVerbose) { context.TraceLog.Add(TraceLevel.Verbose, "Layout Page", "Rendering the resources of page : " + this.PageIndex); } //PDFObjectRef[] annots = this.DoWriteAnnotations(context, writer); //if (null != annots && annots.Length > 0) //{ // writer.BeginDictionaryEntry("Annots"); // writer.WriteArrayRefEntries(true, annots); // writer.EndDictionaryEntry(); //} PDFObjectRef ress = this.DoWriteResource(context, writer); if (ress != null) { writer.WriteDictionaryObjectRefEntry("Resources", ress); } DoWriteArtefacts(context, writer); writer.EndDictionary(); writer.EndPage(context.PageIndex); return(pg); }
public ActionResult Generate() { var generator = new PDFWriter(); var xml = this.Server.UrlDecode(this.Request.Form["grid_xml"]); MemoryStream pdf = generator.Generate(xml); return(File(pdf.ToArray(), generator.ContentType, "grid.pdf")); }
public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { if (null == _refs) { _refs = this.DoOutputToPDF(context, writer); } return(_refs); }
public override void RenderWidthsArrayToPDF(PDFContextBase context, PDFWriter writer) { if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "PDFFontWidths", "No Widths written for empty widths array."); } //Do Nothing }
public static void ProcessExportRequest(HttpContext context) { var writer = new PDFWriter(); var xml = context.Request.Form["grid_xml"]; xml = context.Server.UrlDecode(xml); writer.Generate(xml, context.Response); }
/// <summary> /// Renderes this image xObject if it has not already been rendered. Otherwise returns the last ObjectRef. /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> protected override PDFObjectRef DoRenderToPDF(PDFContextBase context, PDFWriter writer) { if (this.ImageData == null) { throw new NullReferenceException("The Image resource '" + this.Name + "' does not have any ImageData assigned"); } return(this.ImageData.Render(this.Name, context, writer)); }