Programming/c# & winform2020. 10. 22. 15:10

iTextSharp

pdf 파일에 직접 내용을 만들어 넣기(Paragraph 등으로)

[링크 : http://www.csharpstudy.com/Practical/Prac-pdf.aspx]

[링크 : https://stackoverflow.com/questions/11307749/creating-multiple-page-pdf-using-itextsharp]

  [링크 : https://www.nuget.org/packages/iTextSharp/]

 

iTextSharp에 HTML 내용을 넣기

[링크 : https://jujun.tistory.com/118]

 

iTextSharp

Docuement.NewPage()

한페이지 추가하기

[링크 : https://stackoverflow.com/questions/4124106/add-a-page-to-pdf-document-using-itextsharp]

 

 

        private void button2_Click(object sender, EventArgs e)
        {

            Document doc = new Document(iTextSharp.text.PageSize.A4);
            PdfWriter wr = PdfWriter.GetInstance(doc, new FileStream("simple.pdf", FileMode.Create));

            doc.Open();

            doc.AddTitle("Simple PDF 생성 예제");
            doc.AddAuthor("Alex");
            doc.AddCreationDate();

            // 영문쓰기
            doc.Add(new Paragraph("English : How are you?"));
            doc.Add(new Paragraph("국문: 어때요?"));

            doc.NewPage();

            StyleSheet styles = new StyleSheet();
            HtmlWorker hw = new HtmlWorker(doc);

            String html_data = System.IO.File.ReadAllText(@"d:\test.html");
            hw.Parse(new StringReader(html_data));

            doc.NewPage();

            String html_data2 = System.IO.File.ReadAllText(@"d:\test2.html");
            hw.Parse(new StringReader(html_data2));

            hw.EndDocument();
            hw.Close();

            doc.Close();
        }

---

 

 

using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;

using iText.Html2pdf;
using iText.Html2pdf.Attach.Impl;
using iText.Layout.Font;

        private void button2_Click(object sender, EventArgs e)
        {
            String DEST = "hello_world.pdf";

            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();

            PdfWriter writer = new PdfWriter(DEST);
            PdfDocument pdf = new PdfDocument(writer);
            Document document = new Document(pdf);
            document.Add(new Paragraph("Hello World!"));

            HtmlConverter.ConvertToPdf(new FileStream(@"d:\test2.html", FileMode.Open), pdf);
            document.Close();
        }

[링크 : https://kb.itextpdf.com/home/it7kb/examples/pdfhtml-accessible-pdf-creation]

 

[링크 : https://github.com/itext/itextsharp]

[링크 : https://github.com/itext/itext7-dotnet]

 

+

document.Add(new AreaBreak());

[링크 : https://stackoverflow.com/questions/17198337/how-can-i-make-a-page-break-using-itext]

[링크 : https://www.tutorialspoint.com/itext/itext_adding_areabreak.htm]

 

 

+

ConverToPdf() 메소드는 호출 이후 document를 close() 해버린다고.. -_-

The convertToPdf()/ConvertToPdf() methods create a complete PDF file. Any File, FileInfo, OutputStream, PdfWriter (Java/.NET), or PdfDocument (Java/.NET) that is passed to the convertToPdf()/ConvertToPdf() method is closed once the input is parsed and converted to PDF. This might not always be what you want.

In some cases, you want to add some extra information to the Document(Java/.NET), or maybe you don't want to convert the HTML to a PDF file, but to a series of iText objects you can use for a different purpose. That's what the convertToDocument()/ConvertToDocument() and convertToElements()/ConvertToElements() methods are about.

In the C01E07_HelloWorld.java example, we convert our Hello World HTML to a Document (Java/.NET) because we want to add some extra content after we've done parsing the HTML:

[링크 : https://kb.itextpdf.com/.../itext-7-converting-html-to-pdf-with-pdfhtml/chapter-1-hello-html-to-pdf]

'Programming > c# & winform' 카테고리의 다른 글

pdfsharp , migradoc  (0) 2020.10.22
itext7  (0) 2020.10.22
c# print 하기  (0) 2020.10.19
c# printer 사용하기 - printer enumeration  (0) 2020.10.19
c# dialog dual screen  (0) 2020.10.15
Posted by 구차니