本文整理汇总了C#中iTextSharp.text.Document.SetPageSize方法的典型用法代码示例。如果您正苦于以下问题:C# Document.SetPageSize方法的具体用法?C# Document.SetPageSize怎么用?C# Document.SetPageSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.text.Document
的用法示例。
在下文中一共展示了Document.SetPageSize方法的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: MergePdfs
public static byte[] MergePdfs(IEnumerable<byte[]> inputFiles)
{
MemoryStream outputStream = new MemoryStream();
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, outputStream);
document.Open();
PdfContentByte content = writer.DirectContent;
foreach (byte[] input in inputFiles)
{
PdfReader reader = new PdfReader(input);
for (int i = 1; i <= reader.NumberOfPages; i++)
{
document.SetPageSize(reader.GetPageSizeWithRotation(i));
document.NewPage();
PdfImportedPage page = writer.GetImportedPage(reader, i);
int rotation = reader.GetPageRotation(i);
if (rotation == 90 || rotation == 270)
{
content.AddTemplate(page, 0, -1f, 1f, 0, 0,
reader.GetPageSizeWithRotation(i).Height);
}
else
{
content.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
}
}
document.Close();
return outputStream.ToArray();
}
示例3: GeneratePdfReport
public static void GeneratePdfReport(string filepath)
{
FileStream fileStream = new FileStream(filepath, FileMode.Create);
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, fileStream);
document.SetPageSize(PageSize.A3);
document.Open();
var paragraph = new Paragraph("Aggregated Sales Report",
FontFactory.GetFont("Arial", 19, Font.BOLD));
paragraph.SpacingAfter = 20.0f;
paragraph.Alignment = 1;
document.Add(paragraph);
PdfPTable mainTable = new PdfPTable(1);
var reports = GetDayReports();
foreach (var dayReport in reports)
{
var headerCell = new PdfPCell(new Phrase("Date: " + dayReport.FormattedDate));
headerCell.BackgroundColor = new BaseColor(175, 166, 166);
mainTable.AddCell(headerCell);
var table = GenerateReportTable(dayReport);
mainTable.AddCell(table);
}
document.Add(mainTable);
document.Close();
}
示例4: 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();
}
示例5: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
if (ViewName == null)
ViewName = context.RouteData.GetRequiredString("action");
context.Controller.ViewData.Model = Model;
if (context.HttpContext.Request.QueryString["html"] != null && context.HttpContext.Request.QueryString["html"].ToLower().Equals("true"))
{
var view = ViewEngines.Engines.FindView(context, ViewName, null).View;
var viewContext = new ViewContext(context, view, context.Controller.ViewData, context.Controller.TempData, context.HttpContext.Response.Output);
view.Render(viewContext, context.HttpContext.Response.Output);
}
else
{
var memoryStream = new MemoryStream();
var document = new Document(new Rectangle(288f, 144f), 50, 50, 50, 30);
document.SetPageSize(PageSize.A4);
var instance = PdfWriter.GetInstance(document, memoryStream);
instance.CloseStream = false;
document.Open();
var view = ViewEngines.Engines.FindView(context, ViewName, null).View;
var sb = new StringBuilder();
var writer = (TextWriter)new StringWriter(sb);
var viewContext = new ViewContext(context, view, context.Controller.ViewData, context.Controller.TempData, writer);
view.Render(viewContext, writer);
var inp = (Stream)new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString()));
XMLWorkerHelper.GetInstance().ParseXHtml(instance, document, inp, (Stream)null);
document.Close();
new FileStreamResult(new MemoryStream(memoryStream.ToArray()), "application/pdf") { FileDownloadName = FileName + ".pdf" }.ExecuteResult(context);
}
}
示例6: GereRelatorio
public string GereRelatorio()
{
PdfWriter escritor;
string caminho;
string nomeDoArquivoDeSaida;
using (var servico = FabricaGenerica.GetInstancia().CrieObjeto<IServicoDeEmpresa>())
empresa = servico.Obtenha(FabricaDeContexto.GetInstancia().GetContextoAtual().EmpresaLogada.ID);
nomeDoArquivoDeSaida = String.Concat(DateTime.Now.ToString("yyyyMMddhhmmss"), ".pdf");
caminho = String.Concat(HttpContext.Current.Request.PhysicalApplicationPath, UtilidadesWeb.PASTA_LOADS);
_documento = new Document();
_documento.SetPageSize(PageSize.A4.Rotate());
escritor = PdfWriter.GetInstance(_documento,
new FileStream(Path.Combine(caminho, nomeDoArquivoDeSaida),
FileMode.Create));
escritor.PageEvent = new Ouvinte(_Fonte1, _Fonte2, _Fonte3, _Fonte4, empresa);
escritor.AddViewerPreference(PdfName.PRINTSCALING, PdfName.NONE);
escritor.AddViewerPreference(PdfName.PICKTRAYBYPDFSIZE, PdfName.NONE);
_documento.Open();
EscrevaProcessosNoDocumento();
_documento.Close();
return nomeDoArquivoDeSaida;
}
示例7: GraphConvertPdf
public bool GraphConvertPdf(string savename,string savepath,string basepath,string basetype)
{
bool flag = true;
Document doc = new Document();
savename = PdfClass.PdfFileNameConverter(savename);
try
{
PdfWriter.GetInstance(doc, new FileStream(@savepath + "\\" + savename + ".pdf", FileMode.Create));
doc.Open();
int max = Directory.GetFiles(@basepath).Count();
for (int i = 0; i < max; i++)
{
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(@basepath + "\\" + i.ToString() + "." + basetype));
iTextSharp.text.Rectangle pagesize = new iTextSharp.text.Rectangle(image.Width / image.DpiX * 25.4f * 2.834f, image.Height / image.DpiY * 25.4f * 2.834f);
doc.SetPageSize(pagesize);
image.ScaleToFit(doc.PageSize.Width, doc.PageSize.Height);
image.SetAbsolutePosition(0f, 0f);
doc.NewPage();
doc.Add(image);
}
doc.Close();
}
catch
{
flag = false;
}
return flag;
}
示例8: 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).")
);
}
}
示例9: 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");
}
}
示例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: PDFCreator
/// <summary>
/// PDF Creator Helper With No Page Base (Don't want to write a page or report (header or footer)
/// </summary>
/// <param name="PageSize">Page Size - A4 is a default page size. Use Enum iTextSharp.text.PageSize</param>
/// <param name="LandscapeMode">Do you want the pdf in landscape</param>
/// <param name="MarginTop">Top Margin On The Page</param>
/// <param name="MarginRight">Right Margin On The Page</param>
/// <param name="MarginBottom">Bottom Margin On The Page</param>
/// <param name="MarginLeft">Left Margin On The Page</param>
/// <param name="PageEventHandler">A Page Event Class That Will Raise Any Events You Need</param>
public PDFCreator(Rectangle PageSize,
bool LandscapeMode,
float MarginTop,
float MarginRight,
float MarginBottom,
float MarginLeft,
PageEventsBase PageEventHandler)
{
//create the instance of the ITextSharpDocument
Doc = new Document(PageSize, MarginLeft, MarginRight, MarginTop, MarginBottom);
//let's build the memory stream now
Ms = new MemoryStream();
//let's create the new writer and attach the document
Writer = PdfWriter.GetInstance(Doc, Ms);
//add the page events to my custom class
if (PageEventHandler != null)
{
Writer.PageEvent = PageEventHandler;
}
//if you want the pdf in landscape now, then rotate it
if (LandscapeMode)
{
Doc.SetPageSize(PageSize.Rotate());
}
//let's open the document so the developer can do whatever they wan't with it
Doc.Open();
}
示例12: MergeMultiplePDFsToPDF
public string MergeMultiplePDFsToPDF(string[] fileList, string outMergeFile)
{
string returnStr = "";
try
{
int f = 0;
// we create a reader for a certain document
PdfReader reader = new PdfReader(fileList[f]);
// we retrieve the total number of pages
int n = reader.NumberOfPages; //There are " + n + " pages in the original file.
// step 1: creation of a document-object
Document document = new Document(reader.GetPageSizeWithRotation(1));
// step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(outMergeFile, FileMode.Create));
// step 3: we open the document
document.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage page;
int rotation;
// step 4: we add content
while (f < fileList.Length)
{
int i = 0;
while (i < n)
{
i++;
document.SetPageSize(reader.GetPageSizeWithRotation(i));
document.NewPage();
page = writer.GetImportedPage(reader, i);
rotation = reader.GetPageRotation(i);
if (rotation == 90 || rotation == 270)
{
cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
}
else
{
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
//Processed page i
}
f++;
if (f < fileList.Length)
{
reader = new PdfReader(fileList[f]);
// we retrieve the total number of pages
n = reader.NumberOfPages; //There are " + n + " pages in the original file.
}
}
// step 5: we close the document
document.Close();
returnStr = "Succeed!";
}
catch (Exception e)
{
returnStr += e.Message + "<br />";
returnStr += e.StackTrace;
}
return returnStr;
}
示例13: MergeFiles
/// <summary>
/// Merges multiple pdf files into 1 pdf file.
/// </summary>
/// <param name="FilesToMerge">Files to merger (Byte array for each file)</param>
/// <returns>1 file with all the files passed in</returns>
public static byte[] MergeFiles(IEnumerable<byte[]> FilesToMerge)
{
//Declare the memory stream to use
using (var MemoryStreamToWritePdfWith = new MemoryStream())
{
//declare the new document which we will merge all the files into
using (var NewFileToMergeIntoWith = new Document())
{
//holds the byte array which we will return
byte[] ByteArrayToReturn;
//declare the pdf copy to write the data with
using (var PdfCopyWriter = new PdfCopy(NewFileToMergeIntoWith, MemoryStreamToWritePdfWith))
{
//set the page size of the new file
//NewFileToMergeIntoWith.SetPageSize(PageSize.GetRectangle("Letter").Rotate().Rotate());
//go open the new file that we are writing into
NewFileToMergeIntoWith.Open();
//now loop through all the files we want to merge
foreach (var FileToMerge in FilesToMerge)
{
//declare the pdf reader so we can copy it
using (var PdfFileReader = new PdfReader(FileToMerge))
{
//figure out how many pages are in this pdf, so we can add each of the pdf's
int PdfFilePageCount = PdfFileReader.NumberOfPages;
// loop over document pages (start with page 1...not a 0 based index)
for (int i = 1; i <= PdfFilePageCount; i++)
{
//set the file size for this page
NewFileToMergeIntoWith.SetPageSize(PdfFileReader.GetPageSize(i));
//add a new page for the next page
NewFileToMergeIntoWith.NewPage();
//now import the page
PdfCopyWriter.AddPage(PdfCopyWriter.GetImportedPage(PdfFileReader, i));
}
}
}
//now close the new file which we merged everyting into
NewFileToMergeIntoWith.Close();
//grab the buffer and throw it into a byte array to return
ByteArrayToReturn = MemoryStreamToWritePdfWith.GetBuffer();
//flush out the memory stream
MemoryStreamToWritePdfWith.Flush();
}
//now return the byte array
return ByteArrayToReturn;
}
}
}
示例14: 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;
}
}
示例15: 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();
}