本文整理匯總了C#中PdfSharp.Pdf.IO.PdfWriter類的典型用法代碼示例。如果您正苦於以下問題:C# PdfWriter類的具體用法?C# PdfWriter怎麽用?C# PdfWriter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PdfWriter類屬於PdfSharp.Pdf.IO命名空間,在下文中一共展示了PdfWriter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WriteObject
/// <summary>
/// Saves the stream position. 2nd Edition.
/// </summary>
internal override void WriteObject(PdfWriter writer)
{
Debug.Assert(false, "Must not come here!");
// Debug.Assert(this.inStreamOffset <= 0);
// if (this.inStreamOffset == 0)
// {
// //this.InStreamOffset = stream.Position;
// this.document.xrefTable.AddObject(this);
// return Format("{0} {1} obj\n", this.objectID, this.generation);
// }
// else if (this.inStreamOffset == -1)
// {
//
// }
// return null;
//
}
示例2: WriteObject
/// <summary>
/// Writes the string literal with encoding DOCEncoded.
/// </summary>
internal override void WriteObject(PdfWriter writer)
{
writer.WriteBeginObject(this);
writer.Write(new PdfString(this.value, this.flags));
writer.WriteEndObject();
}
示例3: WriteObject
//internal override void WriteDictionaryElement(PdfSharp.Pdf.IO.PdfWriter writer, PdfName key)
//{
// //if (key == Keys.ID)
// //{
// // PdfArray array = Elements[key] as PdfArray;
// // PdfItem item = array.Elements[0];
// // //base.WriteDictionaryElement(writer, key);
// // return;
// //}
// base.WriteDictionaryElement (writer, key);
//}
internal override void WriteObject(PdfWriter writer)
{
// Delete /XRefStm entry, if any
this.elements.Remove(Keys.XRefStm);
// Don't encypt myself
PdfStandardSecurityHandler securityHandler = writer.SecurityHandler;
writer.SecurityHandler = null;
base.WriteObject(writer);
writer.SecurityHandler = securityHandler;
}
示例4: WriteObject
internal override void WriteObject(PdfWriter writer)
{
// HACK: temporarily flip media box if Landscape
PdfRectangle mediaBox = MediaBox;
// TODO: Take /Rotate into account
if (_orientation == PageOrientation.Landscape)
MediaBox = new PdfRectangle(mediaBox.X1, mediaBox.Y1, mediaBox.Y2, mediaBox.X2);
#if true
// Add transparency group to prevent rendering problems of Adobe viewer.
// Update (PDFsharp 1.50 beta 3): Add transparency group only of ColorMode is defined.
// Rgb is the default for the ColorMode, but if user sets it to Undefined then
// we respect this and skip the transparency group.
TransparencyUsed = true; // TODO: check XObjects
if (TransparencyUsed && !Elements.ContainsKey(Keys.Group) &&
_document.Options.ColorMode != PdfColorMode.Undefined)
{
PdfDictionary group = new PdfDictionary();
_elements["/Group"] = group;
if (_document.Options.ColorMode != PdfColorMode.Cmyk)
group.Elements.SetName("/CS", "/DeviceRGB");
else
group.Elements.SetName("/CS", "/DeviceCMYK");
group.Elements.SetName("/S", "/Transparency");
//False is default: group.Elements["/I"] = new PdfBoolean(false);
//False is default: group.Elements["/K"] = new PdfBoolean(false);
}
#endif
#if DEBUG_
PdfItem item = Elements["/MediaBox"];
if (item != null)
item.GetType();
#endif
base.WriteObject(writer);
if (_orientation == PageOrientation.Landscape)
MediaBox = mediaBox;
}
示例5: WriteXRefEnty
/// <summary>
/// Writes the object in PDF iref table format.
/// </summary>
internal void WriteXRefEnty(PdfWriter writer)
{
// PDFsharp does not yet support PDF 1.5 object streams.
// Each line must be exactly 20 bytes long, otherwise Acrobat repairs the file.
string text = String.Format("{0:0000000000} {1:00000} n\n",
this.position, this.objectID.GenerationNumber); // this.InUse ? 'n' : 'f');
writer.WriteRaw(text);
}
示例6: WriteDictionaryElement
/// <summary>
/// Writes a key/value pair of this dictionary. This function is intended to be overridden
/// in derived classes.
/// </summary>
internal virtual void WriteDictionaryElement(PdfWriter writer, PdfName key)
{
if (key == null)
throw new ArgumentNullException("key");
PdfItem item = Elements[key];
#if DEBUG
// TODO: simplify PDFsharp
if (item is PdfObject && ((PdfObject)item).IsIndirect)
{
// Replace an indirect object by its Reference
item = ((PdfObject)item).Reference;
Debug.Assert(false, "Check when we come here.");
}
#endif
key.WriteObject(writer);
item.WriteObject(writer);
writer.NewLine();
}
示例7: WriteObject
/// <summary>
/// Writes the real literal.
/// </summary>
internal override void WriteObject(PdfWriter writer)
{
writer.WriteBeginObject(this);
writer.Write(this.value);
writer.WriteEndObject();
}
示例8: WriteObject
/// <summary>
/// Writes the value in the PDF date format.
/// </summary>
internal override void WriteObject(PdfWriter writer)
{
writer.WriteDocString(ToString());
}
示例9: WriteObject
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);
}
示例10: DoSave
/// <summary>
/// Implements saving a PDF file.
/// </summary>
void DoSave(PdfWriter writer)
{
if (this.pages == null || this.pages.Count == 0)
throw new InvalidOperationException("Cannot save a PDF document with no pages.");
try
{
bool encrypt = this.securitySettings.DocumentSecurityLevel != PdfDocumentSecurityLevel.None;
if (encrypt)
{
PdfStandardSecurityHandler securityHandler = this.securitySettings.SecurityHandler;
if (securityHandler.Reference == null)
this.irefTable.Add(securityHandler);
else
Debug.Assert(this.irefTable.Contains(securityHandler.ObjectID));
this.trailer.Elements[PdfTrailer.Keys.Encrypt] = this.securitySettings.SecurityHandler.Reference;
}
else
this.trailer.Elements.Remove(PdfTrailer.Keys.Encrypt);
PrepareForSave();
if (encrypt)
this.securitySettings.SecurityHandler.PrepareEncryption();
writer.WriteFileHeader(this);
PdfReference[] irefs = this.irefTable.AllReferences;
int count = irefs.Length;
for (int idx = 0; idx < count; idx++)
{
PdfReference iref = irefs[idx];
#if DEBUG_
if (iref.ObjectNumber == 378)
GetType();
#endif
iref.Position = writer.Position;
iref.Value.WriteObject(writer);
}
int startxref = writer.Position;
this.irefTable.WriteObject(writer);
writer.WriteRaw("trailer\n");
this.trailer.Elements.SetInteger("/Size", count + 1);
this.trailer.WriteObject(writer);
writer.WriteEof(this, startxref);
//if (encrypt)
//{
// this.state &= ~DocumentState.SavingEncrypted;
// //this.securitySettings.SecurityHandler.EncryptDocument();
//}
}
finally
{
if (writer != null)
{
writer.Stream.Flush();
// DO NOT CLOSE WRITER HERE
//writer.Close();
}
}
}
示例11: WriteDictionaryElement
/// <summary>
/// Writes a key/value pair of this dictionary. This function is intended to be overridden
/// in derived classes.
/// </summary>
internal virtual void WriteDictionaryElement(PdfWriter writer, PdfName key)
{
if (key == null)
throw new ArgumentNullException("key");
PdfItem item = Elements[key];
key.WriteObject(writer);
item.WriteObject(writer);
writer.NewLine();
}
示例12: Save
/// <summary>
/// Saves the document to the specified stream.
/// </summary>
public void Save(Stream stream, bool closeStream)
{
if (!CanModify)
throw new InvalidOperationException(PSSR.CannotModify);
// TODO: more diagnostic checks
string message = "";
if (!CanSave(ref message))
throw new PdfSharpException(message);
// Get security handler if document gets encrypted
PdfStandardSecurityHandler securityHandler = null;
if (SecuritySettings.DocumentSecurityLevel != PdfDocumentSecurityLevel.None)
securityHandler = SecuritySettings.SecurityHandler;
PdfWriter writer = new PdfWriter(stream, securityHandler);
try
{
DoSave(writer);
}
finally
{
if (stream != null)
{
if (closeStream)
stream.Close();
else
stream.Position = 0; // Reset the stream position if the stream is left open.
}
if (writer != null)
writer.Close(closeStream);
}
}
示例13: Close
/// <summary>
/// Closes this instance.
/// </summary>
public void Close()
{
if (!CanModify)
throw new InvalidOperationException(PSSR.CannotModify);
if (this.outStream != null)
{
// Get security handler if document gets encrypted
PdfStandardSecurityHandler securityHandler = null;
if (SecuritySettings.DocumentSecurityLevel != PdfDocumentSecurityLevel.None)
securityHandler = SecuritySettings.SecurityHandler;
PdfWriter writer = new PdfWriter(this.outStream, securityHandler);
try
{
DoSave(writer);
}
finally
{
writer.Close();
}
}
}
示例14: WriteObject
/// <summary>
/// Writes the name including the leading slash.
/// </summary>
internal override void WriteObject(PdfWriter writer)
{
// TODO: what if unicode character are part of the name?
writer.Write(this);
}
示例15: WriteObject
internal override void WriteObject(PdfWriter writer)
{
// HACK: temporarily flip media box if Landscape
PdfRectangle mediaBox = MediaBox;
// TODO: Take /Rotate into account
if (this.orientation == PageOrientation.Landscape)
MediaBox = new PdfRectangle(mediaBox.X1, mediaBox.Y1, mediaBox.Y2, mediaBox.X2);
#if true
// Add transparency group to prevent rendering problems of Adobe viewer
this.transparencyUsed = true; // TODO: check XObjects
if (this.transparencyUsed && !Elements.Contains(Keys.Group))
{
PdfDictionary group = new PdfDictionary();
this.elements["/Group"] = group;
if (this.document.Options.ColorMode != PdfColorMode.Cmyk)
group.Elements.SetName("/CS", "/DeviceRGB");
else
group.Elements.SetName("/CS", "/DeviceCMYK");
group.Elements.SetName("/S", "/Transparency");
group.Elements["/I"] = new PdfBoolean(false);
group.Elements["/K"] = new PdfBoolean(false);
}
#endif
#if DEBUG_
PdfItem item = Elements["/MediaBox"];
if (item != null)
item.GetType();
#endif
base.WriteObject(writer);
if (this.orientation == PageOrientation.Landscape)
MediaBox = mediaBox;
}