本文整理汇总了C#中Doc.SetInfo方法的典型用法代码示例。如果您正苦于以下问题:C# Doc.SetInfo方法的具体用法?C# Doc.SetInfo怎么用?C# Doc.SetInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doc
的用法示例。
在下文中一共展示了Doc.SetInfo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main(string[] args)
{
// install your own licence
using (Doc doc = new Doc())
{
doc.Read("in.pdf"); // in this PDF the image has an embedded ICC profile, and I must remove them
Console.WriteLine("################################ THROUGH GETINFO ################################");
// Remove the ICC profiles through Get/SetInfo methods
foreach (var item in doc.ObjectSoup)
{
if (item != null && doc.GetInfo(item.ID, "/ColorSpace*[0]*:Name").Equals("ICCBased", StringComparison.InvariantCultureIgnoreCase))
{
int profileId = doc.GetInfoInt(item.ID, "/ColorSpace*[1]:Ref"); // note the [1]: why is it there?
if (profileId != 0)
{
doc.GetInfo(profileId, "Decompress");
string profileData = doc.GetInfo(profileId, "Stream");
// this outputs the ICC profile raw data, with the profile's name somewhere up top
Console.WriteLine(string.Format("ICC profile for object ID {0}: {1}", item.ID, profileData));
doc.SetInfo(profileId, "Stream", string.Empty);
doc.GetInfo(profileId, "Compress");
}
}
}
doc.Save("out-infos.pdf");
doc.Clear();
doc.Read("in.pdf");
Console.WriteLine("################################ THROUGH OBJECTS ################################");
// Remove ICC profiles through the pixmap objects
foreach (var item in doc.ObjectSoup)
{
if (doc.GetInfo(item.ID, "Type") == "jpeg") // only work on PixMaps
{
PixMap pm = (PixMap)item;
if (pm.ColorSpaceType == ColorSpaceType.ICCBased)
{
// pm.ColorSpace.IccProfile is always null so I can't really set it to null or Recolor() it because it would change noting
Console.WriteLine(string.Format("ICC profile for object ID {0}: {1}", item.ID, pm.ColorSpace.IccProfile)); // there should already be an ICC profile (ColorSpaceType = ICCBased) so why does ColorSpace.IccProfile creates one ?
}
}
}
doc.Save("out-objects.pdf");
}
}
示例2: Convert
public byte[] Convert(string link, string width, string height)
{
try
{
var theDoc = new Doc();
theDoc.SetInfo(0, "License", "141-819-141-276-8435-093");
double pageWidth = System.Convert.ToDouble(width.ToUpper().Replace("PX", ""));
double pageHeight = System.Convert.ToDouble(height.ToUpper().Replace("PX", "")) * 1.762;
if (pageHeight>=14400)
{
pageHeight = 14400;
}
theDoc.MediaBox.Width = pageWidth;
theDoc.MediaBox.Height = pageHeight;
theDoc.Rect.Width = pageWidth;
theDoc.Rect.Height = pageHeight;
theDoc.Rect.Inset(5, 5);
theDoc.HtmlOptions.AddLinks = true;
theDoc.Page = theDoc.AddPage();
var theId = theDoc.AddImageUrl(link, false, 0, true);
while (true)
{
if (!theDoc.Chainable(theId))
break;
theDoc.Page = theDoc.AddPage();
theId = theDoc.AddImageToChain(theId);
}
// Link pages together
theDoc.HtmlOptions.LinkPages();
for (var i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
var buffer = theDoc.GetData();
theDoc.Clear();
return buffer;
}
catch (Exception ex)
{
throw ex;
}
}
示例3: ConvertHtmlString
public byte[] ConvertHtmlString(string customData)
{
try
{
var theDoc = new Doc();
theDoc.MediaBox.String = "A4";
theDoc.SetInfo(0, "License", "141-819-141-276-8435-093");
theDoc.Rect.Inset(10, 5);
theDoc.HtmlOptions.AddLinks = true;
theDoc.Page = theDoc.AddPage();
//AbcPdf cache request for 10 min consider for crucial cases.
var theId = theDoc.AddImageHtml(customData);
while (true)
{
if (!theDoc.Chainable(theId))
break;
theDoc.Page = theDoc.AddPage();
theId = theDoc.AddImageToChain(theId);
}
// Link pages together
theDoc.HtmlOptions.LinkPages();
for (var i = 1; i <= theDoc.PageCount; i++)
{
theDoc.PageNumber = i;
theDoc.Flatten();
}
var buffer = theDoc.GetData();
theDoc.Clear();
return buffer;
}
catch (Exception ex)
{
throw ex;
}
}
示例4: AssessmentSummaryToPdfDoc
protected Doc AssessmentSummaryToPdfDoc(PdfRenderSettings settings = null)
{
var dp = DistrictParms.LoadDistrictParms();
if (settings == null) settings = new PdfRenderSettings();
StringWriter sw = new StringWriter();
HtmlTextWriter w = new HtmlTextWriter(sw);
summaryContent.Attributes["style"] = "font-family: Sans-Serif, Arial;font-weight: bold;position: relative;font-size: .8em;";
summaryContent.RenderControl(w);
string result_html = sw.GetStringBuilder().ToString();
int topOffset = settings.HeaderHeight > 0 ? settings.HeaderHeight : 0;
int bottomOffset = settings.FooterHeight > 0 ? settings.FooterHeight : 0;
Doc doc = new Doc();
doc.HtmlOptions.HideBackground = true;
doc.HtmlOptions.PageCacheEnabled = false;
doc.HtmlOptions.UseScript = true;
doc.HtmlOptions.Timeout = 36000;
doc.HtmlOptions.BreakZoneSize = 100; // I experiemented with this being 99% instead of 100%, but you end up with passages getting cut off in unflattering ways. This may lead to more blank space... but I think it's the lessor of evils
doc.HtmlOptions.ImageQuality = 70;
doc.MediaBox.String = "0 0 " + settings.PageWidth + " " + settings.PageHeight;
doc.Rect.String = settings.LeftMargin + " " + (0 + bottomOffset).ToString() + " " + (settings.PageWidth - settings.RightMargin).ToString() + " " + (settings.PageHeight - topOffset).ToString();
doc.HtmlOptions.AddTags = true;
doc.SetInfo(0, "ApplyOnLoadScriptOnceOnly", "1");
List<int> forms = new List<int>();
int theID = doc.AddImageHtml(result_html);
Thinkgate.Base.Classes.Assessment.ChainPDFItems(doc, theID, forms, settings, dp.PdfPrintPageLimit);
if (settings.HeaderHeight > 0 && !String.IsNullOrEmpty(settings.HeaderText))
{
/*HttpServerUtility Server = HttpContext.Current.Server;
headerText = Server.HtmlDecode(headerText);*/
Doc headerDoc = new Doc();
headerDoc.MediaBox.String = settings.LeftMargin + " " + (settings.PageHeight - settings.HeaderHeight).ToString() + " " + (settings.PageWidth - settings.RightMargin).ToString() + " " + settings.PageHeight; //LEFT, BOTTOM,WIDTH, HEIGHT
headerDoc.Rect.String = settings.LeftMargin + " " + (settings.PageHeight - settings.HeaderHeight).ToString() + " " + (settings.PageWidth - settings.RightMargin).ToString() + " " + settings.PageHeight; //LEFT, BOTTOM,WIDTH, HEIGHT
headerDoc.VPos = 0.5;
int headerID = headerDoc.AddImageHtml(settings.HeaderText);
if (!String.IsNullOrEmpty(settings.HeaderText))
{
int form_ref = 0;
for (int i = 1; i <= doc.PageCount; i++)
{
if (form_ref < forms.Count && forms[form_ref] == i)
{
form_ref++;
}
else
{
if (i > 1 || settings.ShowHeaderOnFirstPage)
{
doc.PageNumber = i;
doc.Rect.String = settings.LeftMargin + " " + (settings.PageHeight - settings.HeaderHeight).ToString() + " " + (settings.PageWidth - settings.RightMargin).ToString() + " " + settings.PageHeight; //LEFT, BOTTOM,WIDTH, HEIGHT
doc.VPos = 0.5;
theID = doc.AddImageDoc(headerDoc, 1, null);
theID = doc.AddImageToChain(theID);
}
}
}
}
}
for (int i = 1; i <= doc.PageCount; i++)
{
doc.PageNumber = i;
doc.Flatten();
}
return doc;
}
示例5: ItemAnalysisToPdfDoc
protected Doc ItemAnalysisToPdfDoc(PdfRenderSettings settings = null)
{
if (settings == null) settings = new PdfRenderSettings();
StringWriter sw = new StringWriter();
HtmlTextWriter w = new HtmlTextWriter(sw);
reportHeaderDiv.Controls.Add(LoadPDFHeaderInfo());
barGraphLevelsContainerDiv.Controls.Add(LoadBarGraphLevels());
barGraphPDFContainerDiv.Controls.Add(LoadBarGraphs());
contentDiv.RenderControl(w);
string result_html = sw.GetStringBuilder().ToString();
int topOffset = settings.HeaderHeight > 0 ? settings.HeaderHeight : 0;
int bottomOffset = settings.FooterHeight > 0 ? settings.FooterHeight : 0;
Doc doc = new Doc();
doc.HtmlOptions.HideBackground = true;
doc.HtmlOptions.PageCacheEnabled = false;
doc.HtmlOptions.UseScript = true;
doc.HtmlOptions.Timeout = 36000;
doc.HtmlOptions.BreakZoneSize = 100; // I experiemented with this being 99% instead of 100%, but you end up with passages getting cut off in unflattering ways. This may lead to more blank space... but I think it's the lessor of evils
doc.HtmlOptions.ImageQuality = 70;
doc.MediaBox.String = "0 0 " + settings.PageWidth + " " + settings.PageHeight;
doc.Rect.String = settings.LeftMargin + " " + (0 + bottomOffset).ToString() + " " + (settings.PageWidth - settings.RightMargin).ToString() + " " + (settings.PageHeight - topOffset).ToString();
doc.HtmlOptions.AddTags = true;
doc.SetInfo(0, "ApplyOnLoadScriptOnceOnly", "1");
List<int> forms = new List<int>();
int theID = doc.AddImageHtml(result_html);
while (true)
{
if (!doc.Chainable(theID))
break;
doc.Page = doc.AddPage();
theID = doc.AddImageToChain(theID);
string[] tagIds = doc.HtmlOptions.GetTagIDs(theID);
if (tagIds.Length > 0 && tagIds[0] == "test_header")
forms.Add(doc.PageNumber); // By using GetTagIDs to find if a test header ended up on this page, we can determine whether the page needs a header
if (settings.PossibleForcedBreaks)
{ // only want to take the performance hit if there's a change we're forcing breaks
if (String.IsNullOrEmpty(doc.GetText("Text")))
{ // WSH Found situation where after I added page break always for multi-form, one test that was already breaking properly, added an extra page that was blank between forms. Almost like some amount of HTML had been put there, even though it wasn't any real text. By checking to make sure there is some actual text on page, we can avoid that problem
doc.Delete(doc.Page);
}
}
}
if (settings.HeaderHeight > 0 && !String.IsNullOrEmpty(settings.HeaderText))
{
/*HttpServerUtility Server = HttpContext.Current.Server;
headerText = Server.HtmlDecode(headerText);*/
Doc headerDoc = new Doc();
headerDoc.MediaBox.String = settings.LeftMargin + " " + (settings.PageHeight - settings.HeaderHeight).ToString() + " " + (settings.PageWidth - settings.RightMargin).ToString() + " " + settings.PageHeight; //LEFT, BOTTOM,WIDTH, HEIGHT
headerDoc.Rect.String = settings.LeftMargin + " " + (settings.PageHeight - settings.HeaderHeight).ToString() + " " + (settings.PageWidth - settings.RightMargin).ToString() + " " + settings.PageHeight; //LEFT, BOTTOM,WIDTH, HEIGHT
headerDoc.VPos = 0.5;
int headerID = headerDoc.AddImageHtml(settings.HeaderText);
if (!String.IsNullOrEmpty(settings.HeaderText))
{
int form_ref = 0;
for (int i = 1; i <= doc.PageCount; i++)
{
if (form_ref < forms.Count && forms[form_ref] == i)
{
form_ref++;
}
else
{
if (i > 1 || settings.ShowHeaderOnFirstPage)
{
doc.PageNumber = i;
doc.Rect.String = settings.LeftMargin + " " + (settings.PageHeight - settings.HeaderHeight).ToString() + " " + (settings.PageWidth - settings.RightMargin).ToString() + " " + settings.PageHeight; //LEFT, BOTTOM,WIDTH, HEIGHT
doc.VPos = 0.5;
theID = doc.AddImageDoc(headerDoc, 1, null);
theID = doc.AddImageToChain(theID);
}
}
}
}
}
for (int i = 1; i <= doc.PageCount; i++)
{
doc.PageNumber = i;
doc.Flatten();
}
return doc;
}