Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
다음 코드 스니펫은 Aspose.PDF.Drawing 라이브러리와 함께 작동합니다.
XML 문서에서 PDF 문서를 생성하는 것은 XML 문서가 다양한 내용을 설명할 수 있기 때문에 간단한 작업이 아닙니다. Aspose.PDF for .NET는 XML 문서를 기반으로 PDF를 생성하는 여러 가지 방법을 제공합니다:
XSL (eXtensible Stylesheet Language)은 XML 문서를 다른 XML 문서나 HTML로 변환하기 위한 스타일링 언어입니다. 우리의 경우 XML을 HTML로 변환한 다음 HTML 데이터를 기반으로 PDF를 생성할 수 있습니다.
간단한 CD 카탈로그가 포함된 XML 파일이 있다고 가정해 보겠습니다 (아래 참조).
<?xml version="1.0" encoding="utf-8" ?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>Still got the blues</title>
<artist>Gary Moore</artist>
<country>UK</country>
<company>Virgin records</company>
<price>10.20</price>
<year>1990</year>
</cd>
<cd>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>One night only</title>
<artist>Bee Gees</artist>
<country>UK</country>
<company>Polydor</company>
<price>10.90</price>
<year>1998</year>
</cd>
<cd>
<title>Sylvias Mother</title>
<artist>Dr.Hook</artist>
<country>UK</country>
<company>CBS</company>
<price>8.10</price>
<year>1973</year>
</cd>
<cd>
<title>Maggie May</title>
<artist>Rod Stewart</artist>
<country>UK</country>
<company>Pickwick</company>
<price>8.50</price>
<year>1990</year>
</cd>
<cd>
<title>Romanza</title>
<artist>Andrea Bocelli</artist>
<country>EU</country>
<company>Polydor</company>
<price>10.80</price>
<year>1996</year>
</cd>
<cd>
<title>When a man loves a woman</title>
<artist>Percy Sledge</artist>
<country>USA</country>
<company>Atlantic</company>
<price>8.70</price>
<year>1987</year>
</cd>
<cd>
<title>Black angel</title>
<artist>Savage Rose</artist>
<country>EU</country>
<company>Mega</company>
<price>10.90</price>
<year>1995</year>
</cd>
<cd>
<title>1999 Grammy Nominees</title>
<artist>Many</artist>
<country>USA</country>
<company>Grammy</company>
<price>10.20</price>
<year>1999</year>
</cd>
<cd>
<title>For the good times</title>
<artist>Kenny Rogers</artist>
<country>UK</country>
<company>Mucik Master</company>
<price>8.70</price>
<year>1995</year>
</cd>
<cd>
<title>Big Willie style</title>
<artist>Will Smith</artist>
<country>USA</country>
<company>Columbia</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>Tupelo Honey</title>
<artist>Van Morrison</artist>
<country>UK</country>
<company>Polydor</company>
<price>8.20</price>
<year>1971</year>
</cd>
<cd>
<title>Soulsville</title>
<artist>Jorn Hoel</artist>
<country>Norway</country>
<company>WEA</company>
<price>7.90</price>
<year>1996</year>
</cd>
<cd>
<title>The very best of</title>
<artist>Cat Stevens</artist>
<country>UK</country>
<company>Island</company>
<price>8.90</price>
<year>1990</year>
</cd>
<cd>
<title>Stop</title>
<artist>Sam Brown</artist>
<country>UK</country>
<company>A and M</company>
<price>8.90</price>
<year>1988</year>
</cd>
<cd>
<title>Bridge of Spies</title>
<artist>T`Pau</artist>
<country>UK</country>
<company>Siren</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Private Dancer</title>
<artist>Tina Turner</artist>
<country>UK</country>
<company>Capitol</company>
<price>8.90</price>
<year>1983</year>
</cd>
<cd>
<title>Midt om natten</title>
<artist>Kim Larsen</artist>
<country>EU</country>
<company>Medley</company>
<price>7.80</price>
<year>1983</year>
</cd>
<cd>
<title>Pavarotti Gala Concert</title>
<artist>Luciano Pavarotti</artist>
<country>UK</country>
<company>DECCA</company>
<price>9.90</price>
<year>1991</year>
</cd>
<cd>
<title>The dock of the bay</title>
<artist>Otis Redding</artist>
<country>USA</country>
<company>Stax Records</company>
<price>7.90</price>
<year>1968</year>
</cd>
<cd>
<title>Picture book</title>
<artist>Simply Red</artist>
<country>EU</country>
<company>Elektra</company>
<price>7.20</price>
<year>1985</year>
</cd>
<cd>
<title>Red</title>
<artist>The Communards</artist>
<country>UK</country>
<company>London</company>
<price>7.80</price>
<year>1987</year>
</cd>
<cd>
<title>Unchain my heart</title>
<artist>Joe Cocker</artist>
<country>USA</country>
<company>EMI</company>
<price>8.20</price>
<year>1987</year>
</cd>
</catalog>
이 파일을 PDF로 변환하려면 HTML 레이아웃이 있는 XSL을 생성해야 합니다. 데이터를 테이블로 렌더링해 보겠습니다. 이를 도와줄 XSL 파일은 다음과 같을 수 있습니다:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td>
<xsl:value-of select="title"/>
</td>
<td>
<xsl:value-of select="artist"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
따라서 XML을 변환하고 PDF 문서에 로드해야 합니다. 다음 예제는 이 방법을 보여줍니다:
XSL-FO는 XML 데이터를 화면, 종이 또는 기타 매체로 출력하기 위한 형식을 설명하는 XML 기반 마크업 언어입니다. Aspose.PDF에는 XSL-FO 마크업을 적용하고 PDF 문서를 얻을 수 있는 특별한 클래스가 있습니다.
예를 들어 보겠습니다. 다음은 직원의 샘플 데이터가 포함된 XML 파일입니다.
<?xml version="1.0" encoding="utf-8" ?>
<employees>
<companyname>ABC Inc.</companyname>
<employee>
<id>101</id>
<name>Andrew</name>
<designation>Manager</designation>
</employee>
<employee>
<id>102</id>
<name>Eduard</name>
<designation>Executive</designation>
</employee>
<employee>
<id>103</id>
<name>Peter</name>
<designation>Executive</designation>
</employee>
</employees>
직원 데이터를 테이블로 변환하기 위해 또 다른 파일인 XSL-FO 마크업 파일을 생성해 보겠습니다.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
<xsl:template match="employees">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simpleA4">
<fo:flow flow-name="xsl-region-body">
<fo:block font-size="16pt" font-weight="bold" space-after="5mm">
Company Name: <xsl:value-of select="companyname"/>
</fo:block>
<fo:block font-size="10pt">
<fo:table table-layout="fixed" width="100%" border-collapse="separate">
<fo:table-column column-width="4cm"/>
<fo:table-column column-width="4cm"/>
<fo:table-column column-width="5cm"/>
<fo:table-body>
<xsl:apply-templates select="employee"/>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="employee">
<fo:table-row>
<xsl:if test="designation = 'Manager'">
<xsl:attribute name="font-weight">bold</xsl:attribute>
</xsl:if>
<fo:table-cell>
<fo:block>
<xsl:value-of select="id"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="name"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="designation"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
Aspose.PDF에는 XSL-FO 변환을 적용할 수 있는 특별한 XslFoLoadOptions 클래스가 있습니다. 다음 스니펫은 위에서 설명한 샘플 파일과 함께 이 클래스를 사용하는 방법을 보여줍니다.
때때로 XSL:param을 사용해야 합니다. <xsl:param>
요소는 이름으로 매개변수를 설정하고 선택적으로 해당 매개변수의 기본값을 설정합니다.
이전 사례와 동일한 예를 사용하되 약간의 변경(매개변수 추가)을 하겠습니다. 샘플 데이터가 포함된 XML 파일은 변경되지 않고 …
<?xml version="1.0" encoding="utf-8" ?>
<employees>
<companyname>ABC Inc.</companyname>
<employee>
<id>101</id>
<name>Andrew</name>
<designation>Manager</designation>
</employee>
<employee>
<id>102</id>
<name>Eduard</name>
<designation>Executive</designation>
</employee>
<employee>
<id>103</id>
<name>Peter</name>
<designation>Executive</designation>
</employee>
</employees>
하지만 XSL-FO 마크업 파일에서는 매개변수를 추가합니다: <xsl:param name="isBoldName"></xsl:param>
그리고 이를 Name
열에 적용합니다.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
<xsl:param name="isBoldName"></xsl:param>
<xsl:template match="employees">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simpleA4">
<fo:flow flow-name="xsl-region-body">
<fo:block font-size="16pt" font-weight="bold" space-after="5mm">
Company Name: <xsl:value-of select="companyname"/>
</fo:block>
<fo:block font-size="10pt">
<fo:table table-layout="fixed" width="100%" border-collapse="separate">
<fo:table-column column-width="4cm"/>
<fo:table-column column-width="4cm"/>
<fo:table-column column-width="5cm"/>
<fo:table-body>
<xsl:apply-templates select="employee"/>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="employee">
<fo:table-row>
<xsl:if test="designation = 'Manager'">
<xsl:attribute name="font-weight">bold</xsl:attribute>
</xsl:if>
<fo:table-cell>
<fo:block>
<xsl:value-of select="id"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<xsl:if test="$isBoldName='yes'">
<xsl:attribute name="font-weight">bold</xsl:attribute>
</xsl:if>
<fo:block>
<xsl:value-of select="name"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="designation"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
XSL 매개변수를 추가하려면 자체 XsltArgumentList를 생성하고 XslFoLoadOptions에서 속성으로 설정해야 합니다. 다음 스니펫은 위에서 설명한 샘플 파일과 함께 이 클래스를 사용하는 방법을 보여줍니다.
21.7 이전 버전을 사용하는 경우 다음 기술을 사용하십시오:
XML에서 PDF 문서를 생성하는 또 다른 방법은 Aspose.PDF XML 스키마를 사용하는 것입니다. 이 다이어그램을 사용하여 HTML에서 테이블 레이아웃을 사용하는 것처럼 페이지 레이아웃을 설명할 수 있습니다. 이 방법의 작동 방식을 좀 더 자세히 살펴보겠습니다.
기본 매개변수로 페이지를 정의해 보겠습니다. 우리의 페이지는 A4 페이지 크기를 가지며 텍스트 한 조각만 포함됩니다.
<?xml version="1.0" encoding="utf-8" ?>
<Document xmlns="Aspose.Pdf">
<Page>
<TextFragment>
<TextSegment>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla odio lorem, luctus in lorem vitae, accumsan semper lectus. Cras a auctor leo, et tincidunt lacus.</TextSegment>
</TextFragment>
</Page>
</Document>
PDF 문서를 생성하기 위해 BindXml 메서드를 사용할 것입니다.
새 페이지 크기를 정의하려면 PageInfo
요소를 추가해야 합니다. 다음 예제에서는 A5 페이지 크기와 25mm 및 10mm의 여백을 설정했습니다.
<?xml version="1.0" encoding="utf-8" ?>
<Document xmlns="Aspose.Pdf">
<Page>
<PageInfo IsLandscape="true" Height="595" Width="420">
<Margin Top="70.8661" Bottom="70.8661" Left="28.3465" Right="28.3465" />
</PageInfo>
<TextFragment>
<TextSegment>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla odio lorem, luctus in lorem vitae, accumsan semper lectus. Cras a auctor leo, et tincidunt lacus.</TextSegment>
</TextFragment>
</Page>
</Document>
HTML은 XML과 유사한 태그를 포함하고 있으므로 XML 태그 내에 HTML을 작성할 때 파서는 이를 XML 마크업으로 처리하며 단순히 XML 태그로 인식할 수 없습니다. 이 문제는 XML에서 “CDATA” 섹션을 사용하여 해결할 수 있습니다. CDATA 섹션은 파서에 의해 구문 분석되지 않는 텍스트를 포함하며, 다른 말로 하면 XML 마크업으로 처리되지 않습니다. 다음 샘플 XML 템플릿은 CDATA를 사용하여 XML 마크업 내에 HtmlFragment를 추가하는 방법을 보여줍니다.
<?xml version="1.0" encoding="utf-8" ?>
<Document xmlns="Aspose.Pdf">
<Page id="mainSection">
<HtmlFragment>
<![CDATA[
<font style="font-family:Tahoma; font-size:40px;">This is Html String.</font>
]]>
</HtmlFragment>
</Page>
</Document>
Table
, Row
, Cell
요소는 테이블을 설명하는 데 사용됩니다. 다음 스니펫은 간단한 테이블을 사용하는 방법을 보여줍니다. 이 예제에서는 일부 셀에 Alignment
속성이 있으며 이 속성은 숫자 값을 가집니다:
<?xml version="1.0" encoding="utf-8" ?>
<Document xmlns="Aspose.Pdf">
<Page>
<PageInfo IsLandscape="false" Height="595" Width="420">
<Margin Top="71" Bottom="71" Left="28" Right="28" />
</PageInfo>
<HtmlFragment>
<![CDATA[
<h1 style="font-family:Tahoma; font-size:16pt;">TIMETABLES ON GREENTOWN-BLUEBERG ROUTE</h1>
]]>
</HtmlFragment>
<TextFragment>
<TextSegment>4.1.-28.3.2021 | GREENTOWN → BLUEBERG</TextSegment>
</TextFragment>
<Table ColumnAdjustment="AutoFitToWindow" ColumnWidths ="10 10 10 10">
<DefaultCellPadding Top="5" Left="0" Right="0" Bottom="5" />
<Border>
<Top Color="Black"></Top>
<Bottom Color="Black"></Bottom>
<Left Color="Black"></Left>
<Right Color="Black"></Right>
</Border>
<Margin Top="15" />
<Row BackgroundColor="LightGray" MinRowHeight="20">
<Border>
<Bottom Color="Black"></Bottom>
</Border>
<Cell Alignment="2">
<TextFragment>
<TextSegment>Departure</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Arrival</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Weekday</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Ship</TextSegment>
</TextFragment>
</Cell>
</Row>
<Row>
<Cell Alignment="2">
<TextFragment>
<TextSegment>07.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>09.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Mon-Sat</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Star</TextSegment>
</TextFragment>
</Cell>
</Row>
<Row>
<Cell Alignment="2">
<TextFragment>
<TextSegment>10.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>12.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>every day</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Megastar</TextSegment>
</TextFragment>
</Cell>
</Row>
<Row>
<Cell Alignment="2">
<TextFragment>
<TextSegment>13.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>15.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>every day</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Star</TextSegment>
</TextFragment>
</Cell>
</Row>
<Row>
<Cell Alignment="2">
<TextFragment>
<TextSegment>16.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>18.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>every day</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Megastar</TextSegment>
</TextFragment>
</Cell>
</Row>
<Row>
<Cell Alignment="2">
<TextFragment>
<TextSegment>19.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>21.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>every day</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Star</TextSegment>
</TextFragment>
</Cell>
</Row>
<Row>
<Cell Alignment="2">
<TextFragment>
<TextSegment>22.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>00.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Mon-Fri, Sun</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Megastar</TextSegment>
</TextFragment>
</Cell>
</Row>
</Table>
</Page>
</Document>
테이블은 문서 레이아웃에 사용됩니다. 예를 들어 페이지 헤더를 사용자 정의할 수 있습니다. 이 경우 테이블을 사용하여 헤더를 2열로 나누었습니다.
<?xml version="1.0" encoding="utf-8" ?>
<Document xmlns="Aspose.Pdf">
<Page>
<PageInfo IsLandscape="false" Height="595" Width="420">
<Margin Top="71" Bottom="71" Left="28" Right="28" />
</PageInfo>
<Header>
<Margin Top="20" />
<Table ColumnAdjustment="AutoFitToWindow">
<Row>
<Cell Alignment="1">
<TextFragment>
<TextSegment>Date: 01/01/2021</TextSegment>
</TextFragment>
</Cell>
<Cell Alignment="3">
<TextFragment>
<TextSegment>Page $p / $P</TextSegment>
</TextFragment>
</Cell>
</Row>
</Table>
</Header>
<HtmlFragment>
<![CDATA[
<h1 style="font-family:Tahoma; font-size:16pt;">TIMETABLES ON GREENTOWN-BLUEBERG ROUTE</h1>
]]>
</HtmlFragment>
<TextFragment>
<TextSegment>4.1.-28.3.2021 | GREENTOWN → BLUEBERG</TextSegment>
</TextFragment>
<Table ColumnAdjustment="AutoFitToWindow" ColumnWidths ="10 10 10 10">
<DefaultCellPadding Top="5" Left="0" Right="0" Bottom="5" />
<Border>
<Top Color="Black"></Top>
<Bottom Color="Black"></Bottom>
<Left Color="Black"></Left>
<Right Color="Black"></Right>
</Border>
<Margin Top="15" />
<Row BackgroundColor="LightGray" MinRowHeight="20">
<Border>
<Bottom Color="Black"></Bottom>
</Border>
<Cell Alignment="2">
<TextFragment>
<TextSegment>Departure</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Arrival</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Weekday</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Ship</TextSegment>
</TextFragment>
</Cell>
</Row>
<Row>
<Cell Alignment="2">
<TextFragment>
<TextSegment>07.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>09.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Mon-Sat</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Star</TextSegment>
</TextFragment>
</Cell>
</Row>
<Row>
<Cell Alignment="2">
<TextFragment>
<TextSegment>10.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>12.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>every day</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Megastar</TextSegment>
</TextFragment>
</Cell>
</Row>
<Row>
<Cell Alignment="2">
<TextFragment>
<TextSegment>13.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>15.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>every day</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Star</TextSegment>
</TextFragment>
</Cell>
</Row>
<Row>
<Cell Alignment="2">
<TextFragment>
<TextSegment>16.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>18.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>every day</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Megastar</TextSegment>
</TextFragment>
</Cell>
</Row>
<Row>
<Cell Alignment="2">
<TextFragment>
<TextSegment>19.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>21.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>every day</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Star</TextSegment>
</TextFragment>
</Cell>
</Row>
<Row>
<Cell Alignment="2">
<TextFragment>
<TextSegment>22.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>00.30</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Mon-Fri, Sun</TextSegment>
</TextFragment>
</Cell>
<Cell>
<TextFragment>
<TextSegment>Megastar</TextSegment>
</TextFragment>
</Cell>
</Row>
</Table>
</Page>
</Document>
BindXML() 메서드는 XML 파일 내용을 로드하는 기능을 제공하며 Document.save() 메서드는 출력을 PDF 형식으로 저장하는 데 사용할 수 있습니다. 그러나 변환 중에 XML 내부의 개별 요소에 접근하고 XML을 템플릿으로 사용할 수도 있습니다. 다음 코드 스니펫은 XML 파일에서 TextSegments에 접근하는 단계를 보여줍니다.
<?xml version="1.0" encoding="utf-8" ?>
<Document xmlns="Aspose.Pdf">
<Page id="mainSection">
<TextFragment>
<TextSegment id="boldHtml">segment1</TextSegment>
</TextFragment>
<TextFragment>
<TextSegment id="strongHtml">segment2</TextSegment>
</TextFragment>
</Page>
</Document>
XML 문서에 이미지 또는 그래프 객체와 같은 추가 요소를 추가할 수 있습니다. 다음 스니펫은 이러한 요소를 문서에 추가하는 방법을 보여줍니다.
<Graph Width="20" Height="20">
<Circle PosX="30" PosY="30" Radius="10">
<GraphInfo Color="Red" FillColor="Blue"></GraphInfo>
</Circle>
</Graph>
<Image File="logo.png" Id = "testImg"></Image>
다음 XML 템플릿에는 ID “testImg"가 있는 <Image>
태그가 포함되어 있습니다. 코드에서 이미지 경로를 설정하려는 경우 변환 과정에서 XML 템플릿에서 이미지 요소에 접근하고 원하는 주소로 경로를 설정할 수 있습니다.
<?xml version="1.0" encoding="utf-8" ?>
<Document xmlns="Aspose.Pdf">
<Page id="mainSection">
<PageInfo IsLandscape="true">
<Margin Left="20" Right="20" Top="10" Bottom="30" />
</PageInfo>
<Header>
<Margin Top="20" />
<Table ColumnAdjustment="AutoFitToWindow">
<Row>
<Cell Alignment="1">
<Image File="logo.png" Id = "testImg"></Image>
</Cell>
<Cell Alignment="3">
<TextFragment>
<TextSegment>Page $p / $P</TextSegment>
</TextFragment>
</Cell>
</Row>
</Table>
</Header>
<Table ColumnAdjustment="AutoFitToWindow" ColumnWidths="8 10">
<DefaultCellPadding Top="0" Left="0" Right="0" Bottom="0" />
<Margin Top="15" />
<Row>
<Cell Alignment="1">
<!--Logo-->
<TextFragment>
<TextSegment> Request ID</TextSegment>
<TextState FontSize="14" ForegroundColor="#0e4f9c" FontStyle="1" />
</TextFragment>
<TextFragment>
<TextSegment></TextSegment>
</TextFragment>
<TextFragment>
<TextSegment id="boldtext">Some Bold Text</TextSegment>
<TextState FontSize="14" FontStyle="1"></TextState>
</TextFragment>
</Cell>
</Row>
</Table>
</Page>
</Document>
XML 템플릿에서 이미지 경로를 설정하는 코드는 다음과 같습니다:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.