고급 기능
브라우저로 PDF 다운로드 보내기
ASP.NET 애플리케이션을 개발할 때 때때로 물리적으로 저장하지 않고 웹 브라우저에 PDF 파일을 보내야 할 필요가 있습니다. 이를 달성하기 위해 PDF 문서를 생성한 후 MemoryStream 객체에 저장하고 그 MemoryStream에서 바이트를 Response 객체로 전달할 수 있습니다. 이렇게 하면 브라우저가 생성된 PDF 문서를 다운로드하게 됩니다.
다음 코드 스니펫은 위 기능을 보여줍니다:
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-.NET | |
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(); | |
doc.Pages.Add().Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Hello World")); | |
MemoryStream ms = new MemoryStream(); | |
doc.Save(ms); | |
Response.Clear(); | |
Response.ClearHeaders(); | |
Response.ClearContent(); | |
Response.Charset = "UTF-8"; | |
Response.AddHeader("content-length", ms.Length.ToString()); | |
Response.AddHeader("content-disposition", String.Format("attachment;filename=TestDocument.pdf", "FileName")); | |
Response.ContentType = "application/pdf"; Response.BinaryWrite(ms.ToArray()); | |
Response.Flush(); | |
Response.End(); |
PDF 파일에서 내장 파일 추출
Aspose.PDF는 PDF 형식 파일을 다루는 고급 기능에서 두드러집니다. 다른 도구가 제공하는 기능보다 내장 파일을 더 잘 추출합니다.
Aspose.PDF for .NET을 사용하면 내장된 글꼴, 이미지, 비디오 또는 오디오 등 어떤 내장 파일이든 효율적으로 추출할 수 있습니다. Aspose.PDF for .NET을 사용하면 임베디드 글꼴, 이미지, 비디오 또는 오디오일 수 있는 임베디드 파일을 효율적으로 추출할 수 있습니다.
다음 코드 스니펫은 PDF 파일에서 모든 임베디드 파일을 추출합니다:
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion(); | |
// Load source PDF file | |
Document doc = new Document(dataDir + "input.pdf"); | |
// Save output in XML format | |
doc.Save(dataDir + "PDFToXML_out.xml", SaveFormat.MobiXml); |
라텍스 스크립트를 사용하여 수학 표현식 추가
Aspose.PDF를 사용하면 라텍스 스크립트를 사용하여 PDF 문서 내부에 수학 표현식/공식을 추가할 수 있습니다. 다음 예제는 표 셀 내부에 수학 공식을 추가하는 두 가지 방법을 보여줍니다:
서문과 문서 환경 없이
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); | |
// Create a new Document Object | |
Document doc = new Document(); | |
// Add Page in Pages Collection | |
Page page = doc.Pages.Add(); | |
// Create a Table | |
Table table = new Table(); | |
// Add a row into Table | |
Row row = table.Rows.Add(); | |
// Add Cell with Latex Script to add methematical expressions/formulae | |
string latexText1 = "$123456789+\\sqrt{1}+\\int_a^b f(x)dx$"; | |
Cell cell = row.Cells.Add(); | |
cell.Margin = new MarginInfo { Left = 20, Right = 20, Top = 20, Bottom = 20 }; | |
// Second LatexFragment constructor bool parameter provides LaTeX paragraph indents elimination. | |
LatexFragment ltext1 = new LatexFragment(latexText1, true); | |
cell.Paragraphs.Add(ltext1); | |
// Add table inside page | |
page.Paragraphs.Add(table); | |
// Save the document | |
doc.Save(dataDir + "LatextScriptInPdf_out.pdf"); |
서문과 문서 환경 포함
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_AsposePdf_Text(); | |
// Create a new Document Object | |
Document doc = new Document(); | |
// Add Page in Pages Collection | |
Page page = doc.Pages.Add(); | |
// Create a Table | |
Table table = new Table(); | |
// Add a row into Table | |
Row row = table.Rows.Add(); | |
// Add Cell with Latex Script to add methematical expressions/formulae | |
string latexText2 = @"\documentclass{article} | |
\begin{document} | |
Latex and the document class will normally take care of page layout issues for you. For submission to an academic publication, this entire topic will be out | |
\end{document}"; | |
Cell cell = row.Cells.Add(); | |
cell.Margin = new MarginInfo { Left = 20, Right = 20, Top = 20, Bottom = 20 }; | |
HtmlFragment text2 = new HtmlFragment(latexText2); | |
cell.Paragraphs.Add(text2); | |
// Add table inside page | |
page.Paragraphs.Add(table); | |
// Save the document | |
doc.Save(dataDir + "LatextScriptInPdf2_out.pdf"); |
라텍스 태그 지원
Latex 태그 지원
align 환경은 amsmath 패키지에 정의되어 있으며, proof 환경은 amsthm 패키지에 정의되어 있습니다. 따라서 문서 전문에 \usepackage 명령을 사용하여 이러한 패키지를 지정해야 합니다. 이는 LaTeX 텍스트를 다음 코드 샘플에 표시된 것처럼 문서 환경에 넣어야 함을 의미합니다.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET | |
var dataDir = RunExamples.GetDataDir_AsposePdf_Text(); | |
var s = @" | |
\usepackage{amsmath,amsthm} | |
\begin{document} | |
\begin{proof} The proof is a follows: | |
\begin{align} | |
(x+y)^3&=(x+y)(x+y)^2 | |
(x+y)(x^2+2xy+y^2)\\ | |
&=x^3+3x^2y+3xy^3+x^3.\qedhere | |
\end{align} | |
\end{proof} | |
\end{document}"; | |
var doc = new Document(); | |
var page = doc.Pages.Add(); | |
var latex = new LatexFragment(s); | |
page.Paragraphs.Add(latex); | |
doc.Save(dataDir + "Script_out.pdf"); |