This article is purely informative, and the PDF document operation C# code is posted.You need to add a reference to compile normally.
I won’t say much nonsense, I will just post code to you.
The code is as follows:
using ; using ; using ; namespace { /// <summary> /// PDF document operation class /// </summary> //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //PDFOperation pdf = new PDFOperation(); //(new FileStream(path, )); //(@"C:\Windows\Fonts\"); //("Test Document (Generation Time: " + + ")", 15, 1, 20, 0, 0); //(); //------------------------------------------------------------------------------------- public class PDFOperation { #region constructor /// <summary> /// Constructor /// </summary> public PDFOperation() { rect = PageSize.A4; document = new Document(rect); } /// <summary> /// Constructor /// </summary> /// <param name="type">Page size (such as "A4")</param> public PDFOperation(string type) { SetPageSize(type); document = new Document(rect); } /// <summary> /// Constructor /// </summary> /// <param name="type">Page size (such as "A4")</param> /// <param name="marginLeft">Distance from the left border</param> /// <param name="marginRight">Distance from the right border</param> /// <param name="marginTop">Distance from the upper border</param> /// <param name="marginBottom">Distance from the lower border</param> public PDFOperation(string type, float marginLeft, float marginRight, float marginTop, float marginBottom) { SetPageSize(type); document = new Document(rect, marginLeft, marginRight, marginTop, marginBottom); } #endregion #region Private Field private Font font; private Rectangle rect; //Document size private Document document;//Document object private BaseFont basefont;//Font #endregion #region Set fonts /// <summary> /// Set font /// </summary> public void SetBaseFont(string path) { basefont = (path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); } /// <summary> /// Set font /// </summary> /// <param name="size">Font size</param> public void SetFont(float size) { font = new Font(basefont, size); } #endregion #region Set page size /// <summary> /// Set page size /// </summary> /// <param name="type">Page size (such as "A4")</param> public void SetPageSize(string type) { switch (()) { case "A4": rect = PageSize.A4; break; case "A8": rect = PageSize.A8; break; } } #endregion #region Instantiated Document /// <summary> /// Instantiate the document /// </summary> /// <param name="os">Document-related information (such as path, opening method, etc.)</param> public void GetInstance(Stream os) { (document, os); } #endregion #region Open the document object /// <summary> /// Open the document object /// </summary> /// <param name="os">Document-related information (such as path, opening method, etc.)</param> public void Open(Stream os) { GetInstance(os); (); } #endregion #region Close open document /// <summary> /// Close the open document /// </summary> public void Close() { (); } #endregion #region Add paragraph /// <summary> /// Add paragraph /// </summary> /// <param name="content">Content</param> /// <param name="fontsize">Font size</param> public void AddParagraph(string content, float fontsize) { SetFont(fontsize); Paragraph pra = new Paragraph(content, font); (pra); } /// <summary> /// Add paragraph /// </summary> /// <param name="content">Content</param> /// <param name="fontsize">Font size</param> /// <param name="Alignment">Alignment (1 is centered, 0 is left, and 2 is right)</param> /// <param name="SpacingAfter">Number of empty lines after segment (0 is the default value)</param> /// <param name="SpacingBefore">Number of empty lines before segment (0 is the default value)</param> /// <param name="MultipliedLeading">Line spacing (0 is the default)</param> public void AddParagraph(string content, float fontsize, int Alignment, float SpacingAfter, float SpacingBefore, float MultipliedLeading) { SetFont(fontsize); Paragraph pra = new Paragraph(content, font); = Alignment; if (SpacingAfter != 0) { = SpacingAfter; } if (SpacingBefore != 0) { = SpacingBefore; } if (MultipliedLeading != 0) { = MultipliedLeading; } (pra); } #endregion #region Add image /// <summary> /// Add picture /// </summary> /// <param name="path">Picture path</param> /// <param name="Alignment">Alignment (1 is centered, 0 is left, and 2 is right)</param> /// <param name="newWidth">Image width (0 is the default value, if the width is greater than the page width, it will be scaled by ratio)</param> /// <param name="newHeight">High picture</param> public void AddImage(string path, int Alignment, float newWidth, float newHeight) { Image img = (path); = Alignment; if (newWidth != 0) { (newWidth, newHeight); } else { if ( > PageSize.) { (, * / ); } } (img); } #endregion #region Add links, points /// <summary> /// Add a link /// </summary> /// <param name="Content">Link text</param> /// <param name="FontSize">FontSize</param> /// <param name="Reference">Link address</param> public void AddAnchorReference(string Content, float FontSize, string Reference) { SetFont(FontSize); Anchor auc = new Anchor(Content, font); = Reference; (auc); } /// <summary> /// Add link point /// </summary> /// <param name="Content">Link text</param> /// <param name="FontSize">FontSize</param> /// <param name="Name">Link name</param> public void AddAnchorName(string Content, float FontSize, string Name) { SetFont(FontSize); Anchor auc = new Anchor(Content, font); = Name; (auc); } #endregion } }
I would like to remind you that you need to add a reference to compile normally.