public override void WriteFontObject(TPdfStream DataStream, TXRefSection XRef) { XRef.SetObjectOffset(FontObjId, DataStream); TIndirectRecord.SaveHeader(DataStream, FontObjId); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.FontName)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.SubtypeName, FontType()); TDictionaryRecord.SaveKey(DataStream, TPdfToken.BaseFontName, GetFontName(Embed, Subset)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.EncodingName, EncodingType()); long fc = FirstChar; if (fc < 0) { fc = 0; } TDictionaryRecord.SaveKey(DataStream, TPdfToken.FirstCharName, PdfConv.LongToString(fc)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.LastCharName, PdfConv.LongToString(LastChar)); XRef.SetObjectOffset(FontDescriptorId, DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontDescriptorName, TIndirectRecord.GetCallObj(FontDescriptorId)); SaveWidths(DataStream); TDictionaryRecord.EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); SaveFontDescriptor(DataStream, FontDescriptorId, XRef, Embed, Subset); }
public void WriteGStateObject(TPdfStream DataStream, TXRefSection XRef) { XRef.SetObjectOffset(GStateObjId, DataStream); TIndirectRecord.SaveHeader(DataStream, GStateObjId); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.ExtGStateName)); TDictionaryRecord.SaveKey(DataStream, Operator, PdfConv.CoordsToString(Alpha / 255.0)); if (SMask != null) { SMaskObjId = XRef.GetNewObject(DataStream); TDictionaryRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.SMaskName)); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.MaskName)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.SName, TPdfTokens.GetString(TPdfToken.AlphaName)); TDictionaryRecord.Write(DataStream, TPdfTokens.GetString(TPdfToken.GName) + " "); TIndirectRecord.CallObj(DataStream, SMaskObjId); TDictionaryRecord.EndDictionary(DataStream); } TDictionaryRecord.EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); if (SMask != null) { WriteSMaskObject(DataStream, XRef); } }
protected void SaveFontDescriptor(TPdfStream DataStream, int FontDescriptorId, TXRefSection XRef, bool Embed, bool Subset) { XRef.SetObjectOffset(FontDescriptorId, DataStream); TIndirectRecord.SaveHeader(DataStream, FontDescriptorId); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.FontDescriptorName)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontNameName, GetFontName(Embed, Subset)); string BBox = TPdfTokens.GetString(TPdfToken.OpenArray) + FTrueTypeData.BoundingBox.GetBBox(FTrueTypeData.UnitsPerEm) + TPdfTokens.GetString(TPdfToken.CloseArray); TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontBBoxName, BBox); TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontAscentName, (int)Math.Round(FTrueTypeData.Ascent * 1000F / FTrueTypeData.UnitsPerEm)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontDescentName, (int)Math.Round(FTrueTypeData.Descent * 1000F / FTrueTypeData.UnitsPerEm)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.CapHeightName, (int)Math.Round(FTrueTypeData.CapHeight * 1000F / FTrueTypeData.UnitsPerEm)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.ItalicAngleName, FTrueTypeData.ItalicAngle.ToString(CultureInfo.InvariantCulture)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.StemVName, 80); //StemV info is not present on a true type font. 80 seems to be what adobe writes. TDictionaryRecord.SaveKey(DataStream, TPdfToken.FlagsName, FTrueTypeData.FontFlags); if (Embed) { TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontFile2Name, TIndirectRecord.GetCallObj(EmbeddedData.GetStreamId(DataStream, XRef))); } TDictionaryRecord.EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); EmbeddedData.WriteFont(DataStream, XRef, FCompress); }
private void SaveToUnicode(TPdfStream DataStream, TXRefSection XRef) { XRef.SetObjectOffset(ToUnicodeId, DataStream); TIndirectRecord.SaveHeader(DataStream, ToUnicodeId); XRef.SetObjectOffset(ToUnicodeLenId, DataStream); TStreamRecord.BeginSave(DataStream, ToUnicodeLenId, FCompress); long StartStream = DataStream.Position; bool Compressing = DataStream.Compress; try { DataStream.Compress = FCompress; WriteToUnicodeData(DataStream); } finally { DataStream.Compress = Compressing; } long EndStream = DataStream.Position; TStreamRecord.EndSave(DataStream); TIndirectRecord.SaveTrailer(DataStream); XRef.SetObjectOffset(ToUnicodeLenId, DataStream); TIndirectRecord.SaveHeader(DataStream, ToUnicodeLenId); TPdfBaseRecord.WriteLine(DataStream, (EndStream - StartStream).ToString(CultureInfo.InvariantCulture)); TIndirectRecord.SaveTrailer(DataStream); }
internal void SaveToStream(TPdfStream DataStream, TXRefSection XRef, TAcroFormRecord AcroForm) { XRef.SetObjectOffset(Id, DataStream); TIndirectRecord.SaveHeader(DataStream, Id); BeginDictionary(DataStream); SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.PagesName)); SaveKids(DataStream, XRef); SaveKey(DataStream, TPdfToken.CountName, FList.Count); WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.ResourcesName)); Resources.SaveResourceDesc(DataStream, XRef, true); EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); int aCount = FList.Count; for (int i = 0; i < aCount; i++) { TPageInfo PInfo = FList[i]; TPageRecord.SaveToStream(DataStream, Id, PInfo, AcroForm, XRef, i, aCount); PInfo.Annots.SaveToStream(DataStream, XRef); } Resources.SaveObjects(DataStream, XRef); }
internal void SaveBookmarks(TPdfStream DataStream, TXRefSection XRef, int OutlinesId) { if (OutlinesId < 0) { return; } int FirstId = -1; int LastId = -1; int NextId = XRef.GetNewObject(DataStream); int AllOpenCount = 0; SaveBookmarkObjects(DataStream, XRef, Bookmarks, OutlinesId, NextId, ref FirstId, ref LastId, ref AllOpenCount); XRef.SetObjectOffset(OutlinesId, DataStream); TIndirectRecord.SaveHeader(DataStream, OutlinesId); TDictionaryRecord.BeginDictionary(DataStream); if (FirstId >= 0) { TDictionaryRecord.SaveKey(DataStream, TPdfToken.FirstName, TIndirectRecord.GetCallObj(FirstId)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.LastName, TIndirectRecord.GetCallObj(LastId)); //LastId must be positive if FirstId is positive. } if (AllOpenCount > 0) { TDictionaryRecord.SaveKey(DataStream, TPdfToken.CountName, AllOpenCount); } TDictionaryRecord.EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); }
private static void Saven2(TPdfStream DataStream, TXRefSection XRef, TPdfVisibleSignature VSig, int n2Id) { string s = String.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3} {4} {5} cm ", VSig.Rect.Width, 0, 0, VSig.Rect.Height, 0, 0); string StreamContents = "q " + s + TPdfTokens.GetString(TPdfToken.ImgPrefix) + "0 Do Q"; XRef.SetObjectOffset(n2Id, DataStream); TIndirectRecord.SaveHeader(DataStream, n2Id); BeginDictionary(DataStream); WriteCommonXObject(DataStream, VSig.Rect, StreamContents); TPdfResources Resources = new TPdfResources(null, false, null); using (MemoryStream ImgStream = new MemoryStream(VSig.ImageData)) { Resources.AddImage(null, ImgStream, FlxConsts.NoTransparentColor, false); } SaveProcSet(DataStream, XRef, true); SaveResourcesImgXObject(DataStream, XRef, Resources); EndDictionary(DataStream); WriteStream(DataStream, StreamContents); TIndirectRecord.SaveTrailer(DataStream); Resources.SaveObjects(DataStream, XRef); }
internal static void SaveToStream(TPdfStream DataStream, TXRefSection XRef, int CatalogId, int PagesId, int BookmarksId, int AcroFormId, int PermsId, TPdfToken PageLayout) { XRef.SetObjectOffset(CatalogId, DataStream); TIndirectRecord.SaveHeader(DataStream, CatalogId); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.CatalogName)); SaveKey(DataStream, TPdfToken.PagesName, TIndirectRecord.GetCallObj(PagesId)); if (BookmarksId >= 0) { SaveKey(DataStream, TPdfToken.OutlinesName, TIndirectRecord.GetCallObj(BookmarksId)); } if (PageLayout != TPdfToken.None) { SaveKey(DataStream, TPdfToken.PageModeName, TPdfTokens.GetString(PageLayout)); } if (AcroFormId >= 0) { SaveKey(DataStream, TPdfToken.AcroFormName, TIndirectRecord.GetCallObj(AcroFormId)); } if (PermsId >= 0) { SaveKey(DataStream, TPdfToken.PermsName, TIndirectRecord.GetCallObj(PermsId)); } EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); }
public void WritePatternObject(TPdfStream DataStream, TXRefSection XRef) { byte[] PatternDef = GetPatternDef(); XRef.SetObjectOffset(PatternObjId, DataStream); TIndirectRecord.SaveHeader(DataStream, PatternObjId); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.PatternName)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.PatternTypeName, "1"); TDictionaryRecord.SaveKey(DataStream, TPdfToken.PaintTypeName, "1"); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TilingTypeName, "2"); TDictionaryRecord.SaveKey(DataStream, TPdfToken.BBoxName, String.Format(CultureInfo.InvariantCulture, "[0 0 {0} {1}]", ImgWidth, ImgHeight)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.XStepName, PdfConv.CoordsToString(ImgWidth)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.YStepName, PdfConv.CoordsToString(ImgHeight)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.MatrixName, PdfConv.ToString(PatternMatrix, true)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.LengthName, PatternDef.Length); TDictionaryRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.ResourcesName)); TDictionaryRecord.BeginDictionary(DataStream); TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.XObjectName)); TDictionaryRecord.BeginDictionary(DataStream); ImageDef.WriteImage(DataStream, XRef); TDictionaryRecord.EndDictionary(DataStream); TDictionaryRecord.EndDictionary(DataStream); TDictionaryRecord.EndDictionary(DataStream); TStreamRecord.BeginSave(DataStream); DataStream.Write(PatternDef); TStreamRecord.EndSave(DataStream); TIndirectRecord.SaveTrailer(DataStream); ImageDef.WriteImageObject(DataStream, XRef); }
public void WritePatternObject(TPdfStream DataStream, TXRefSection XRef) { int MatrixSize; byte[] PatternDef = GetPattern(out MatrixSize); XRef.SetObjectOffset(PatternObjId, DataStream); TIndirectRecord.SaveHeader(DataStream, PatternObjId); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.PatternName)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.PatternTypeName, "1"); TDictionaryRecord.SaveKey(DataStream, TPdfToken.PaintTypeName, "2"); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TilingTypeName, "2"); TDictionaryRecord.SaveKey(DataStream, TPdfToken.BBoxName, String.Format(CultureInfo.InvariantCulture, "[0 0 {0} {0}]", MatrixSize)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.XStepName, MatrixSize.ToString(CultureInfo.InvariantCulture)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.YStepName, MatrixSize.ToString(CultureInfo.InvariantCulture)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.LengthName, PatternDef.Length); TDictionaryRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.ResourcesName)); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.EndDictionary(DataStream); TDictionaryRecord.EndDictionary(DataStream); TStreamRecord.BeginSave(DataStream); DataStream.Write(PatternDef); TStreamRecord.EndSave(DataStream); TIndirectRecord.SaveTrailer(DataStream); }
public static void WriteColorSpaceObject(TPdfStream DataStream, TXRefSection XRef, int ColorSpaceId) { XRef.SetObjectOffset(ColorSpaceId, DataStream); TIndirectRecord.SaveHeader(DataStream, ColorSpaceId); TPdfBaseRecord.Write(DataStream, TPdfTokens.GetString(TPdfToken.OpenArray)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.PatternName, TPdfTokens.GetString(TPdfToken.DeviceRGBName)); TPdfBaseRecord.Write(DataStream, TPdfTokens.GetString(TPdfToken.CloseArray)); TIndirectRecord.SaveTrailer(DataStream); }
private void CreateNewPage(TPdfStream DataStream, TXRefSection XRef, TPaperDimensions PageSize) { int PageId = XRef.GetNewObject(DataStream); int ContentId = XRef.GetNewObject(DataStream); PageTree.AddPage(PageId, ContentId, PageSize); TIndirectRecord.SaveHeader(DataStream, ContentId); LengthId = XRef.GetNewObject(DataStream); TStreamRecord.BeginSave(DataStream, LengthId, Compress); DataStream.Compress = Compress; StartStream = DataStream.Position; }
private void SaveAction(TPdfStream DataStream, TXRefSection XRef) { XRef.SetObjectOffset(ActionId, DataStream); TIndirectRecord.SaveHeader(DataStream, ActionId); BeginDictionary(DataStream); TPdfBaseRecord.Write(DataStream, String.Format(CultureInfo.InvariantCulture, TPdfTokens.GetString(TPdfToken.LinkData), FURL)); EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); }
internal void FinishPage(TPdfStream DataStream, TXRefSection XRef) { DataStream.FlushEndText(); DataStream.Compress = false; EndStream = DataStream.Position; TStreamRecord.EndSave(DataStream); TIndirectRecord.SaveTrailer(DataStream); XRef.SetObjectOffset(LengthId, DataStream); TIndirectRecord.SaveHeader(DataStream, LengthId); TPdfBaseRecord.WriteLine(DataStream, (EndStream - StartStream).ToString(CultureInfo.InvariantCulture)); TIndirectRecord.SaveTrailer(DataStream); }
public override void WriteFontObject(TPdfStream DataStream, TXRefSection XRef) { XRef.SetObjectOffset(FontObjId, DataStream); TIndirectRecord.SaveHeader(DataStream, FontObjId); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.FontName)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.SubtypeName, TPdfTokens.GetString(TPdfToken.Type1Name)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.BaseFontName, GetFontName()); TDictionaryRecord.SaveKey(DataStream, TPdfToken.EncodingName, EncodingType()); TDictionaryRecord.EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); }
private static void Saven0(TPdfStream DataStream, TXRefSection XRef, TPdfVisibleSignature VSig, int n0Id) { string StreamContents = "% DSBlank"; XRef.SetObjectOffset(n0Id, DataStream); TIndirectRecord.SaveHeader(DataStream, n0Id); BeginDictionary(DataStream); WriteCommonXObject(DataStream, new RectangleF(0, 0, 100, 100), StreamContents); SaveProcSet(DataStream, XRef, false); EndDictionary(DataStream); EndDictionary(DataStream); WriteStream(DataStream, StreamContents); TIndirectRecord.SaveTrailer(DataStream); }
public void WritePatternObject(TPdfStream DataStream, TXRefSection XRef) { XRef.SetObjectOffset(PatternObjId, DataStream); TIndirectRecord.SaveHeader(DataStream, PatternObjId); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.PatternName)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.PatternTypeName, "2"); TDictionaryRecord.SaveKey(DataStream, TPdfToken.MatrixName, DrawingMatrix); WriteShadingDictionary(DataStream, XRef); TDictionaryRecord.EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); }
protected void BeginSaveToStream(TPdfStream DataStream, TXRefSection XRef) { XRef.SetObjectOffset(FId, DataStream); TIndirectRecord.SaveHeader(DataStream, FId); BeginDictionary(DataStream); SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.AnnotName)); SaveKey(DataStream, TPdfToken.RectName, TPdfTokens.GetString(TPdfToken.OpenArray) + String.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", x1, y1, x1 + Width, y1 + Height) + TPdfTokens.GetString(TPdfToken.CloseArray) ); DateTime dt = DateTime.Now; SaveKey(DataStream, TPdfToken.MName, TDateRecord.GetDate(dt)); }
internal void SaveToStream(TPdfStream DataStream, TXRefSection XRef, int MDPId) { if (GetId(DataStream, XRef, MDPId) < 0) { return; } if (MDPId < 0) { return; } XRef.SetObjectOffset(PermsId, DataStream); TIndirectRecord.SaveHeader(DataStream, PermsId); BeginDictionary(DataStream); SaveKey(DataStream, TPdfToken.DocMDPName, TIndirectRecord.GetCallObj(MDPId)); EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); }
internal void SaveToStream(TPdfStream DataStream, TXRefSection XRef, TPageInfo ParentPage) { if (FieldList.Count <= 0) { return; //No AcroForm in this file. } XRef.SetObjectOffset(GetId(DataStream, XRef), DataStream); TIndirectRecord.SaveHeader(DataStream, FId); BeginDictionary(DataStream); SaveKey(DataStream, TPdfToken.FieldsName, FieldList.GetCallArray(DataStream, XRef, false)); SaveKey(DataStream, TPdfToken.SigFlagsName, SigFlags); EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); FieldList.SaveToStream(DataStream, XRef, ParentPage); }
internal void SaveToStream(TPdfStream DataStream, TXRefSection XRef, TPdfProperties p) { InfoId = XRef.GetNewObject(DataStream); TIndirectRecord.SaveHeader(DataStream, InfoId); BeginDictionary(DataStream); if (p.Title != null && p.Title.Length > 0) { SaveUnicodeKey(DataStream, TPdfToken.TitleName, p.Title); } if (p.Author != null && p.Author.Length > 0) { SaveUnicodeKey(DataStream, TPdfToken.AuthorName, p.Author); } if (p.Subject != null && p.Subject.Length > 0) { SaveUnicodeKey(DataStream, TPdfToken.SubjectName, p.Subject); } if (p.Keywords != null && p.Keywords.Length > 0) { SaveUnicodeKey(DataStream, TPdfToken.KeywordsName, p.Keywords); } if (p.Creator != null && p.Creator.Length > 0) { SaveUnicodeKey(DataStream, TPdfToken.CreatorName, p.Creator); } string Producer = TPdfTokens.GetString(TPdfToken.Producer); if (!PdfWriter.FTesting) { Producer += Assembly.GetExecutingAssembly().GetName().Version.ToString(); } if (Producer != null && Producer.Length > 0) { SaveUnicodeKey(DataStream, TPdfToken.ProducerName, Producer); } DateTime dt = DateTime.Now; SaveKey(DataStream, TPdfToken.CreationDateName, TDateRecord.GetDate(dt)); EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); }
private void SaveSigDictionary(TPdfStream DataStream, TXRefSection XRef, int SigDictionaryId) { XRef.SetObjectOffset(SigDictionaryId, DataStream); TIndirectRecord.SaveHeader(DataStream, SigDictionaryId); BeginDictionary(DataStream); SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.SigName)); SaveKey(DataStream, TPdfToken.FilterName, TPdfTokens.GetString(TPdfToken.Adobe_PPKLiteName)); SaveKey(DataStream, TPdfToken.SubFilterName, TPdfTokens.GetString(TPdfToken.adbe_pkcs7_detachedName)); DateTime dt = Signature.SignDate; if (dt == DateTime.MinValue) { dt = DateTime.Now; } SaveKey(DataStream, TPdfToken.MName, TDateRecord.GetDate(dt)); if (Signature.Location != null) { SaveUnicodeKey(DataStream, TPdfToken.LocationName, Signature.Location); } if (Signature.Reason != null) { SaveUnicodeKey(DataStream, TPdfToken.ReasonName, Signature.Reason); } if (Signature.ContactInfo != null) { SaveUnicodeKey(DataStream, TPdfToken.ContactInfoName, Signature.ContactInfo); } Write(DataStream, TPdfTokens.GetString(TPdfToken.ContentsName)); //After writing "contents" we need to write the pkcs data, but it can not be written yet since we didn't calculate it. PKCSSize = DataStream.GetEstimatedLength() * 2 + 2; //*2 +2 is because the real string will be hexa, and each byte is 2 bytes, plus "<" and ">" to mark an hexa string. int SignOffset = 50 + PKCSSize; //The 50 is for /Contents[a b c d] where a, b, c and d are of variable length. DataStream.GoVirtual(SignOffset); SaveReferenceDict(DataStream, XRef); EndSaveToStream(DataStream, XRef); }
//For unicode fonts, we actually need to write 2 fonts, one type 0 and one CID. public override void WriteFontObject(TPdfStream DataStream, TXRefSection XRef) { //Save Type 0 Font. XRef.SetObjectOffset(FontObjId, DataStream); TIndirectRecord.SaveHeader(DataStream, FontObjId); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.FontName)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.SubtypeName, TPdfTokens.GetString(TPdfToken.Type0Name)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.BaseFontName, GetFontName(true, Subset)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.EncodingName, EncodingType()); XRef.SetObjectOffset(CIDFontId, DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.DescendantFontsName, TPdfTokens.GetString(TPdfToken.OpenArray) + TIndirectRecord.GetCallObj(CIDFontId) + TPdfTokens.GetString(TPdfToken.CloseArray)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.ToUnicodeName, TIndirectRecord.GetCallObj(ToUnicodeId)); TDictionaryRecord.EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); //Save CID Font. XRef.SetObjectOffset(CIDFontId, DataStream); TIndirectRecord.SaveHeader(DataStream, CIDFontId); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.FontName)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.SubtypeName, TPdfTokens.GetString(TPdfToken.CIDFontType2Name)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.BaseFontName, GetFontName(true, Subset)); TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.CIDSystemInfo)); TPdfBaseRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.CIDToGIDMap)); SaveWidths(DataStream); XRef.SetObjectOffset(FontDescriptorId, DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.FontDescriptorName, TIndirectRecord.GetCallObj(FontDescriptorId)); TDictionaryRecord.EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); SaveToUnicode(DataStream, XRef); SaveFontDescriptor(DataStream, FontDescriptorId, XRef, true, Subset); }
private static void SaveFRM(TPdfStream DataStream, TXRefSection XRef, TPdfVisibleSignature VSig, int FRMId) { string StreamContents = "q 1 0 0 1 0 0 cm /n0 Do Q" + TPdfTokens.NewLine + "q 1 0 0 1 0 0 cm /n2 Do Q"; XRef.SetObjectOffset(FRMId, DataStream); TIndirectRecord.SaveHeader(DataStream, FRMId); BeginDictionary(DataStream); WriteCommonXObject(DataStream, VSig.Rect, StreamContents); int n0Id = XRef.GetNewObject(DataStream); int n2Id = XRef.GetNewObject(DataStream); SaveProcSet(DataStream, XRef, false); SaveResourcesSecondXObject(DataStream, n0Id, n2Id); EndDictionary(DataStream); WriteStream(DataStream, StreamContents); TIndirectRecord.SaveTrailer(DataStream); Saven0(DataStream, XRef, VSig, n0Id); Saven2(DataStream, XRef, VSig, n2Id); }
private static void SaveAPObj(TPdfStream DataStream, TXRefSection XRef, int APId, TPdfVisibleSignature VSig) { string StreamContents = "q 1 0 0 1 0 0 cm /FRM Do Q"; //AP Object XRef.SetObjectOffset(APId, DataStream); TIndirectRecord.SaveHeader(DataStream, APId); BeginDictionary(DataStream); WriteCommonXObject(DataStream, VSig.Rect, StreamContents); int FRMId = XRef.GetNewObject(DataStream); SaveProcSet(DataStream, XRef, false); SaveResourcesFirstXObject(DataStream, XRef, FRMId); EndDictionary(DataStream); WriteStream(DataStream, StreamContents); TIndirectRecord.SaveTrailer(DataStream); SaveFRM(DataStream, XRef, VSig, FRMId); }
internal static void SaveToStream(TPdfStream DataStream, int PageListId, TPageInfo PageInfo, TAcroFormRecord AcroForm, TXRefSection XRef, int PageNumber, int PageCount) { XRef.SetObjectOffset(PageInfo.Id, DataStream); TIndirectRecord.SaveHeader(DataStream, PageInfo.Id); BeginDictionary(DataStream); SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.PageName)); SaveKey(DataStream, TPdfToken.ParentName, TIndirectRecord.GetCallObj(PageListId)); SaveKey(DataStream, TPdfToken.ContentsName, TIndirectRecord.GetCallObj(PageInfo.Contents.Id)); SaveKey(DataStream, TPdfToken.MediaBoxName, TPdfTokens.GetString(TPdfToken.OpenArray) + "0 0 " + PdfConv.CoordsToString(PageInfo.Contents.PageSize.Width * 72 / 100) + " " + PdfConv.CoordsToString(PageInfo.Contents.PageSize.Height * 72 / 100) + TPdfTokens.GetString(TPdfToken.CloseArray) ); if (PageInfo.Annots.HasAnnots(AcroForm, PageNumber, PageCount)) { SaveKey(DataStream, TPdfToken.AnnotsName, PageInfo.Annots.GetCallArray(DataStream, XRef, AcroForm, PageNumber, PageCount)); } EndDictionary(DataStream); TIndirectRecord.SaveTrailer(DataStream); }
public void WriteSMaskObject(TPdfStream DataStream, TXRefSection XRef) { //Actually write stream XRef.SetObjectOffset(SMaskObjId, DataStream); TIndirectRecord.SaveHeader(DataStream, SMaskObjId); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.LengthName, SMask.Length); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.XObjectName)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.SubtypeName, TPdfTokens.GetString(TPdfToken.FormName)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.BBoxName, BBox); TDictionaryRecord.WriteLine(DataStream, TPdfTokens.GetString(TPdfToken.GroupName)); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.SName, TPdfTokens.GetString(TPdfToken.TransparencyName)); TDictionaryRecord.EndDictionary(DataStream); TDictionaryRecord.EndDictionary(DataStream); TStreamRecord.BeginSave(DataStream); TStreamRecord.Write(DataStream, SMask); TStreamRecord.EndSave(DataStream); TIndirectRecord.SaveTrailer(DataStream); }
internal void WriteFont(TPdfStream DataStream, TXRefSection XRef, bool Compress) { if (AlreadySaved || ObjectId == -1) { return; } AlreadySaved = true; int EmbeddedLenId = XRef.GetNewObject(DataStream); //Stream Length XRef.SetObjectOffset(ObjectId, DataStream); TIndirectRecord.SaveHeader(DataStream, ObjectId); byte[] FontData = TrueTypeData.SubsetFontData(SubsetCMap); TStreamRecord.BeginSave(DataStream, EmbeddedLenId, Compress, FontData.Length); long StartStream = DataStream.Position; bool Compressing = DataStream.Compress; try { DataStream.Compress = Compress; DataStream.Write(FontData); } finally { DataStream.Compress = Compressing; } long EndStream = DataStream.Position; TStreamRecord.EndSave(DataStream); TIndirectRecord.SaveTrailer(DataStream); XRef.SetObjectOffset(EmbeddedLenId, DataStream); TIndirectRecord.SaveHeader(DataStream, EmbeddedLenId); TPdfBaseRecord.WriteLine(DataStream, (EndStream - StartStream).ToString(CultureInfo.InvariantCulture)); TIndirectRecord.SaveTrailer(DataStream); }
public void WriteFunctionObject(TPdfStream DataStream, TXRefSection XRef, bool Compress) { XRef.SetObjectOffset(GetFunctionObjId(DataStream, XRef), DataStream); TIndirectRecord.SaveHeader(DataStream, FunctionObjId); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.FunctionTypeName, FunctionType); if (Domain != null) { TDictionaryRecord.SaveKey(DataStream, TPdfToken.DomainName, PdfConv.ToString(Domain, true)); } if (Range != null) { TDictionaryRecord.SaveKey(DataStream, TPdfToken.RangeName, PdfConv.ToString(Range, true)); } SaveExtraKeys(DataStream, XRef, Compress); TDictionaryRecord.EndDictionary(DataStream); SaveStream(DataStream, XRef, Compress); TIndirectRecord.SaveTrailer(DataStream); }
private void WriteImageOrMaskObject(TPdfStream DataStream, TXRefSection XRef, bool IsSMask, int ObjId) { XRef.SetObjectOffset(ObjId, DataStream); TIndirectRecord.SaveHeader(DataStream, ObjId); TDictionaryRecord.BeginDictionary(DataStream); TDictionaryRecord.SaveKey(DataStream, TPdfToken.TypeName, TPdfTokens.GetString(TPdfToken.XObjectName)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.SubtypeName, TPdfTokens.GetString(TPdfToken.ImageName)); TDictionaryRecord.SaveKey(DataStream, TPdfToken.WidthName, FImageWidth); TDictionaryRecord.SaveKey(DataStream, TPdfToken.HeightName, FImageHeight); if (!IsSMask) { TDictionaryRecord.SaveKey(DataStream, TPdfToken.BitsPerComponentName, FBitsPerComponent); if (FSMask != null) { TDictionaryRecord.SaveKey(DataStream, MaskOrSMask, TIndirectRecord.GetCallObj(SMaskId)); } if (FMask != null) { TDictionaryRecord.SaveKey(DataStream, TPdfToken.MaskName, FMask); } TDictionaryRecord.SaveKey(DataStream, TPdfToken.LengthName, (int)FImage.Length); TDictionaryRecord.SaveKey(DataStream, TPdfToken.ColorSpaceName, FColorSpace); //This value is stored on the PropertyTagExifColorSpace property of the image for JPEG. if (FDecodeParmsName != null) { TDictionaryRecord.SaveKey(DataStream, TPdfToken.DecodeParmsName, FDecodeParmsName); } } else { if (OneBitMask != null && FMask == null) { SaveSMaskAsMask(DataStream); } else { TDictionaryRecord.SaveKey(DataStream, TPdfToken.BitsPerComponentName, 8); TDictionaryRecord.SaveKey(DataStream, TPdfToken.LengthName, (int)FSMask.Length); TDictionaryRecord.SaveKey(DataStream, TPdfToken.ColorSpaceName, TPdfTokens.GetString(TPdfToken.DeviceGrayName)); //This value is stored on the PropertyTagExifColorSpace property of the image for JPEG. if (FDecodeParmsSMask != null) { TDictionaryRecord.SaveKey(DataStream, TPdfToken.DecodeParmsName, FDecodeParmsSMask); } } } TDictionaryRecord.SaveKey(DataStream, TPdfToken.FilterName, FFilterName); TDictionaryRecord.EndDictionary(DataStream); TStreamRecord.BeginSave(DataStream); if (!IsSMask) { DataStream.Write(FImage); } else { if (OneBitMask != null) { DataStream.Write(OneBitMask); } else { DataStream.Write(FSMask); } } TStreamRecord.EndSave(DataStream); TIndirectRecord.SaveTrailer(DataStream); }