本文整理汇总了C#中iTextSharp.text.Document.SetMargins方法的典型用法代码示例。如果您正苦于以下问题:C# Document.SetMargins方法的具体用法?C# Document.SetMargins怎么用?C# Document.SetMargins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.text.Document
的用法示例。
在下文中一共展示了Document.SetMargins方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreatePdf
public override byte[] CreatePdf(List<PdfContentParameter> contents, string[] images, int type)
{
var document = new Document();
float docHeight = document.PageSize.Height - heightOffset;
document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
document.SetMargins(50, 50, 10, 40);
var output = new MemoryStream();
var writer = PdfWriter.GetInstance(document, output);
writer.PageEvent = new HeaderFooterHandler(type);
document.Open();
document.Add(contents[0].Table);
for (int i = 0; i < images.Length; i++)
{
document.NewPage();
float subtrahend = document.PageSize.Height - heightOffset;
iTextSharp.text.Image pool = iTextSharp.text.Image.GetInstance(images[i]);
pool.Alignment = 3;
pool.ScaleToFit(document.PageSize.Width - (document.RightMargin * 2), subtrahend);
//pool.ScaleAbsolute(document.PageSize.Width - (document.RightMargin * 2), subtrahend);
document.Add(pool);
}
document.Close();
return output.ToArray();
}
示例2: CreatePdf
public void CreatePdf(Project project, Stream writeStream)
{
var document = new Document();
var writer = PdfWriter.GetInstance(document, writeStream);
// landscape
document.SetPageSize(PageSize.A4.Rotate());
document.SetMargins(36f, 36f, 36f, 36f); // 0.5 inch margins
// metadata
document.AddCreator("EstimatorX.com");
document.AddKeywords("estimation");
document.AddAuthor(project.Creator);
document.AddSubject(project.Name);
document.AddTitle(project.Name);
document.Open();
AddName(project, document);
AddDescription(project, document);
AddAssumptions(project, document);
AddFactors(project, document);
AddTasks(project, document);
AddSummary(project, document);
writer.Flush();
document.Close();
}
示例3: TransformHtml2Pdf
protected override void TransformHtml2Pdf() {
Document doc = new Document(PageSize.A1.Rotate());
PdfWriter pdfWriter = PdfWriter.GetInstance(doc, new FileStream(outPdf, FileMode.Create));
doc.SetMargins(doc.LeftMargin - 10, doc.RightMargin - 10, doc.TopMargin, doc.BottomMargin);
doc.Open();
CssFilesImpl cssFiles = new CssFilesImpl();
cssFiles.Add(
XMLWorkerHelper.GetCSS(
File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + testName +
Path.DirectorySeparatorChar + "complexDiv02_files" + Path.DirectorySeparatorChar +
"minimum0.css")));
cssFiles.Add(
XMLWorkerHelper.GetCSS(
File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + testName +
Path.DirectorySeparatorChar + "complexDiv02_files" + Path.DirectorySeparatorChar +
"print000.css")));
cssFiles.Add(XMLWorkerHelper.GetCSS(File.OpenRead(RESOURCES + @"\tool\xml\examples\" + "sampleTest.css")));
StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);
HtmlPipelineContext hpc =
new HtmlPipelineContext(
new CssAppliersImpl(new XMLWorkerFontProvider(RESOURCES + @"\tool\xml\examples\fonts")));
hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(Tags.GetHtmlTagProcessorFactory());
hpc.SetImageProvider(new SampleTestImageProvider());
HtmlPipeline htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, pdfWriter));
IPipeline pipeline = new CssResolverPipeline(cssResolver, htmlPipeline);
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser p = new XMLParser(true, worker, Encoding.GetEncoding("UTF-8"));
p.Parse(File.OpenRead(inputHtml), Encoding.GetEncoding("UTF-8"));
doc.Close();
}
示例4: ParseXfaOnlyXML
virtual public void ParseXfaOnlyXML() {
StreamReader bis = File.OpenText(RESOURCE_TEST_PATH + SNIPPETS + TEST + "snippet.html");
Document doc = new Document(PageSize.A4);
float margin = utils.ParseRelativeValue("10%", PageSize.A4.Width);
doc.SetMargins(margin, margin, margin, margin);
PdfWriter writer = null;
try {
writer = PdfWriter.GetInstance(doc, new FileStream(
TARGET + TEST + "_charset.pdf", FileMode.Create));
}
catch (DocumentException e) {
Console.WriteLine(e);
}
CssFilesImpl cssFiles = new CssFilesImpl();
cssFiles.Add(XMLWorkerHelper.GetInstance().GetDefaultCSS());
StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);
HtmlPipelineContext hpc = new HtmlPipelineContext(null);
hpc.SetAcceptUnknown(true)
.AutoBookmark(true)
.SetTagFactory(Tags.GetHtmlTagProcessorFactory())
.CharSet(Encoding.GetEncoding("ISO-8859-1"));
IPipeline pipeline = new CssResolverPipeline(cssResolver,
new HtmlPipeline(hpc, new PdfWriterPipeline(doc, writer)));
XMLWorker worker = new XMLWorker(pipeline, true);
doc.Open();
XMLParser p = new XMLParser(true, worker);
p.Parse(bis);
doc.Close();
}
示例5: Test
public void Test() {
String file = "tagged_pdf_end_page.pdf";
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(OUTPUT_FOLDER + file, FileMode.Create));
writer.PdfVersion = PdfWriter.VERSION_1_7;
writer.SetTagged();
writer.CreateXmpMetadata();
document.SetMargins(10, 10, 60, 10);
PdfPTable headerTable = new PdfPTable(1);
PdfPageHeader header = new CustomPdfPageHeader(writer, 10, headerTable);
writer.PageEvent = header;
document.Open();
PdfPTable table = CreateContent();
document.Add(table);
document.Close();
// compare
CompareTool compareTool = new CompareTool().SetFloatRelativeError(1e-4f);
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + file, TEST_RESOURCES_PATH + file,
OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例6: Parser
public Byte[] Parser(string html)
{
//pasos paraa volver una caddena en formato de string en formato html a pdf
Document document = new Document();//PageSize.LETTER, 3, 2, 2, 2
var diezpoint = iTextSharp.text.Utilities.MillimetersToPoints(10);
document.SetMargins(this.MarginLeft * diezpoint, this.MarginRight * diezpoint, this.MarginTop * diezpoint, this.MarginBotton * diezpoint);
//PdfWriter pdfWrite = PdfWriter.GetInstance(document, new FileStream(@"D:\fmEP02.pdf", FileMode.Create));
MemoryStream ms = new MemoryStream();
PdfWriter pdfWrite = PdfWriter.GetInstance(document, ms);
PDFHyF pdfhyf = new PDFHyF();
pdfhyf.SetHeader(new HeaderHyF(Logo, Codigo, Nombre, Version, FechaVersion));
pdfWrite.PageEvent = pdfhyf;
document.Open();
string htmlText = html;
XMLWorkerHelper.GetInstance().ParseXHtml(pdfWrite, document, new StringReader(htmlText.Replace("<br>", "<br/>")));
document.Close();
pdfWrite.Close();
//pasos para volver el archivo pdf en datos binarios
//PdfReader pdfReader = new PdfReader("D://fmEP02.pdf");
PdfReader pdfReader = new PdfReader(ms.ToArray());
MemoryStream stream = new MemoryStream();
PdfStamper stamper = new PdfStamper(pdfReader, stream);
stream.Flush();
stamper.Close();
pdfReader.Close();
stream.Close();
return stream.ToArray();
}
示例7: startGenerateReport
void startGenerateReport()
{
if (!string.IsNullOrEmpty(txtPath.Text))
{
document = new Document(PageSize.A3, 0, 0, 0, 0);
document.SetPageSize(PageSize.A3.Rotate());
document.SetMargins(0, 0, 60f, 40f);
var tempFileName = ("E:\\report.pdf");
fileStream = new System.IO.FileStream(tempFileName, System.IO.FileMode.Create);
writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, fileStream);
var logoSetting = _reportSettingRepository.GetKeyValue(Repository.Utils.ReportSettingsKeys.Logo);
iTextEvents = new ITextEvents();
iTextEvents.Logo = logoSetting != null ? logoSetting.Value : string.Empty;
writer.PageEvent = iTextEvents;
document.Open();
var cb = writer.DirectContent;
drawFrontPage();
var drawGranulometryOnPDF = new DrawGranulometryOnPDF(_granulometryControl, document, progressBar1, panel1, iTextEvents);
drawGranulometryOnPDF.DrawCompleted += drawGranulometryOnPDF_DrawCompleted;
}
else
{
MessageBox.Show("Please provide path");
}
}
示例8: MakePdf
protected override void MakePdf(string outPdf) {
Document doc = new Document(PageSize.A4.Rotate());
PdfWriter pdfWriter = PdfWriter.GetInstance(doc, new FileStream(outPdf, FileMode.Create));
doc.SetMargins(45, 45, 0, 100);
doc.Open();
CssFilesImpl cssFiles = new CssFilesImpl();
cssFiles.Add(
XMLWorkerHelper.GetCSS(
File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + Path.DirectorySeparatorChar + testName +
Path.DirectorySeparatorChar + "complexDiv_files" + Path.DirectorySeparatorChar +
"main.css")));
cssFiles.Add(
XMLWorkerHelper.GetCSS(
File.OpenRead(RESOURCES + Path.DirectorySeparatorChar + testPath + Path.DirectorySeparatorChar + testName +
Path.DirectorySeparatorChar + "complexDiv_files" + Path.DirectorySeparatorChar +
"widget082.css")));
StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);
HtmlPipelineContext hpc =
new HtmlPipelineContext(
new CssAppliersImpl(new XMLWorkerFontProvider(RESOURCES + @"\tool\xml\examples\fonts")));
hpc.SetAcceptUnknown(true).AutoBookmark(true).SetTagFactory(Tags.GetHtmlTagProcessorFactory());
hpc.SetImageProvider(new SampleTestImageProvider());
hpc.SetPageSize(doc.PageSize);
HtmlPipeline htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, pdfWriter));
IPipeline pipeline = new CssResolverPipeline(cssResolver, htmlPipeline);
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser p = new XMLParser(true, worker, Encoding.GetEncoding("UTF-8"));
p.Parse(File.OpenRead(inputHtml), Encoding.GetEncoding("UTF-8"));
doc.Close();
}
示例9: Write
// ===========================================================================
public void Write(Stream stream)
{
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter.GetInstance(document, stream);
document.SetPageSize(PageSize.A5);
document.SetMargins(36, 72, 108, 180);
document.SetMarginMirroring(true);
// step 3
document.Open();
// step 4
document.Add(new Paragraph(
"The left margin of this odd page is 36pt (0.5 inch); " +
"the right margin 72pt (1 inch); " +
"the top margin 108pt (1.5 inch); " +
"the bottom margin 180pt (2.5 inch).")
);
Paragraph paragraph = new Paragraph();
paragraph.Alignment = Element.ALIGN_JUSTIFIED;
for (int i = 0; i < 20; i++)
{
paragraph.Add("Hello World! Hello People! " +
"Hello Sky! Hello Sun! Hello Moon! Hello Stars!"
);
}
document.Add(paragraph);
document.Add(new Paragraph(
"The right margin of this even page is 36pt (0.5 inch); " +
"the left margin 72pt (1 inch).")
);
}
}
示例10: Process
/*public MemoryStream Process(IEnumerable<Student> students)
{
}*/
public MemoryStream Process(IEnumerable<ClassEnrollment> enrollments)
{
//Loop through each enrollment to process one report card per student
var pdfReaders = enrollments.Select(enrollment => new PdfReader(Process(enrollment, enrollment.StudentGrades.ToList()).ToArray())).ToList();
//Now merge all the pdf streams into one document
var outputStream = new MemoryStream();
var pdfDoc = new Document();
pdfDoc.SetMargins(0, 0, 0, 0);
var writer = PdfWriter.GetInstance(pdfDoc, outputStream);
pdfDoc.Open();
var pdfContentByte = writer.DirectContent;
foreach (var reader in pdfReaders)
{
for (var page = 1; page <= reader.NumberOfPages; page++)
{
var importedPage = writer.GetImportedPage(reader, page);
pdfDoc.SetPageSize(importedPage.BoundingBox);
pdfDoc.NewPage();
pdfContentByte.AddTemplate(importedPage, 0, 0);
}
}
outputStream.Flush();
pdfDoc.Close();
outputStream.Close();
return outputStream;
}
示例11: CompoundIdtoPDFStream
public static MemoryStream CompoundIdtoPDFStream(string compoundId)
{
Document document = new Document(new Rectangle(147f, 68f));
document.SetMargins(0f, 0f, 0f, 0f);
// string fontsfolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts);
Font font = FontFactory.GetFont("Arial", 28, Color.BLACK);
MemoryStream stream = new MemoryStream();
try
{
PdfWriter pdfWriter = PdfWriter.GetInstance(document, stream);
pdfWriter.CloseStream = false;
Paragraph para = new Paragraph(compoundId, font);
para.Alignment = Element.ALIGN_CENTER;
document.Open();
document.Add(para);
}
catch (DocumentException de)
{
Console.Error.WriteLine(de.Message);
}
catch (IOException ioe)
{
Console.Error.WriteLine(ioe.Message);
}
document.Close();
stream.Flush();
stream.Position = 0;
return stream;
}
示例12: Build
public void Build()
{
iTextSharp.text.Document doc = null;
try
{
// Initialize the PDF document
doc = new Document();
iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(doc,
new System.IO.FileStream(System.IO.Directory.GetCurrentDirectory() + "\\ScienceReport.pdf",
System.IO.FileMode.Create));
// Set margins and page size for the document
doc.SetMargins(50, 50, 50, 50);
// There are a huge number of possible page sizes, including such sizes as
// EXECUTIVE, POSTCARD, LEDGER, LEGAL, LETTER_LANDSCAPE, and NOTE
doc.SetPageSize(new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.LETTER.Width,
iTextSharp.text.PageSize.LETTER.Height));
// Add metadata to the document. This information is visible when viewing the
// document properities within Adobe Reader.
doc.AddTitle("My Science Report");
doc.AddCreator("M. Lichtenberg");
doc.AddKeywords("paper airplanes");
// Add Xmp metadata to the document.
this.CreateXmpMetadata(writer);
// Open the document for writing content
doc.Open();
// Add pages to the document
this.AddPageWithBasicFormatting(doc);
this.AddPageWithInternalLinks(doc);
this.AddPageWithBulletList(doc);
this.AddPageWithExternalLinks(doc);
this.AddPageWithImage(doc, System.IO.Directory.GetCurrentDirectory() + "\\FinalGraph.jpg");
// Add page labels to the document
iTextSharp.text.pdf.PdfPageLabels pdfPageLabels = new iTextSharp.text.pdf.PdfPageLabels();
pdfPageLabels.AddPageLabel(1, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Basic Formatting");
pdfPageLabels.AddPageLabel(2, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Internal Links");
pdfPageLabels.AddPageLabel(3, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Bullet List");
pdfPageLabels.AddPageLabel(4, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "External Links");
pdfPageLabels.AddPageLabel(5, iTextSharp.text.pdf.PdfPageLabels.EMPTY, "Image");
writer.PageLabels = pdfPageLabels;
}
catch (iTextSharp.text.DocumentException dex)
{
// Handle iTextSharp errors
}
finally
{
// Clean up
doc.Close();
doc = null;
}
}
示例13: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
var Response = context.HttpContext.Response;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "filename=foo.pdf");
var document = new Document();
document.SetPageSize(new Rectangle(72 * W, 72 * H));
document.SetMargins(14f, 0f, 3.6f, 1f);
var w = PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
dc = w.DirectContent;
var ctl = new MailingController {UseTitles = titles, UseMailFlags = useMailFlags};
IEnumerable<MailingController.MailingInfo> q = null;
switch (format)
{
case "Individual":
case "GroupAddress":
q = ctl.FetchIndividualList(sort, qid);
break;
case "FamilyMembers":
case "Family":
q = ctl.FetchFamilyList(sort, qid);
break;
case "ParentsOf":
q = ctl.FetchParentsOfList(sort, qid);
break;
case "CouplesEither":
q = ctl.FetchCouplesEitherList(sort, qid);
break;
case "CouplesBoth":
q = ctl.FetchCouplesBothList(sort, qid);
break;
}
AddLabel(document, "=========", $"{Util.UserName}\n{q.Count()},{DateTime.Now:g}", String.Empty);
foreach (var m in q)
{
var label = m.LabelName;
if (m.CoupleName.HasValue() && format.StartsWith("Couples"))
label = m.CoupleName;
var address = "";
if (m.MailingAddress.HasValue())
address = m.MailingAddress;
else
{
var sb = new StringBuilder(m.Address);
if (m.Address2.HasValue())
sb.AppendFormat("\n{0}", m.Address2);
sb.AppendFormat("\n{0}", m.CSZ);
address = sb.ToString();
}
AddLabel(document, label, address, Util.PickFirst(m.CellPhone.FmtFone("C "), m.HomePhone.FmtFone("H ")));
}
document.Close();
}
示例14: CreatePDFFile
/// <summary>
/// Function which will create pdf document and save in the server folder
/// </summary>
private void CreatePDFFile()
{
Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 10, 10);
try
{
string pdfFilePath = Server.MapPath(".") + "/pdf/myPdf.pdf";
//Create Document class object and set its size to letter and give space left, right, Top, Bottom Margin
PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(pdfFilePath, FileMode.Create));
doc.Open();//Open Document to write
doc.SetMargins(0, 0, 0, 0);
//Write some content into pdf file
// Paragraph paragraph = new Paragraph("Profile Pictures");
// Now image in the pdf file
string imageFilePath = Server.MapPath(".") + "/image/photo (2).jpg";
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath);
//Resize image depend upon your need
jpg.ScaleToFit(700f, 800f);
jpg.Border = Rectangle.BOX;
jpg.BorderColor = Color.BLACK;
jpg.BorderWidth = 15f;
// jpg.GetImageRotation();
jpg.RotationDegrees = 270f;
//Give space before image
// jpg.SpacingBefore = 30f;
//Give some space after the image
// jpg.SpacingAfter = 1f;
jpg.Alignment = Element.ALIGN_CENTER;
// doc.Add(paragraph); // add paragraph to the document
doc.Add(jpg); //add an image to the created pdf document
}
catch (DocumentException docEx)
{
//handle pdf document exception if any
}
catch (IOException ioEx)
{
// handle IO exception
}
catch (Exception ex)
{
// ahndle other exception if occurs
}
finally
{
//Close document and writer
doc.Close();
}
}
示例15: Document
bool IPDFConverter.ConvertToPDF(string Src, out string PDFFile)
{
System.IO.FileInfo info = new System.IO.FileInfo(Src);
PDFFile = Src;
bool succeeded = true;
Gnome.Vfs.Uri uri = new Gnome.Vfs.Uri(Gnome.Vfs.Uri.GetUriFromLocalPath(info.FullName));
Gnome.Vfs.MimeType mime = new Gnome.Vfs.MimeType(uri);
if (mime != null && mime.Name.ToLower().StartsWith("image"))
{
Document document = null;
try
{
PDFFile = String.Format("/tmp/{0}.pdf", info.Name);
Image logo = Image.GetInstance(info.FullName);
// step 1: creation of a document-object
//Rectangle pageSize = new Rectangle(logo.GetRectangle(0, 0));
document = new Document();
document.SetMargins(0, 0, 0, 0);
document.SetPageSize(new Rectangle(logo.Width, logo.Height));
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.GetInstance(document, new FileStream(PDFFile, FileMode.Create));
// step 3: we open the document
document.Open();
// step 4: we Add some paragraphs to the document
document.Add(logo);
}
catch(DocumentException de)
{
Console.Error.WriteLine(de.Message);
}
catch(IOException ioe)
{
Console.Error.WriteLine(ioe.Message);
}
// step 5: we close the document
document.Close();
}
if (! System.IO.File.Exists(PDFFile))
{
PDFFile = null;
succeeded = false;
}
return succeeded;
}