|
Rank: Newbie Groups: Member
Joined: 10/20/2022 Posts: 5
|
We need to include an XML document as part of a PDF document. We render the document to PDF like any other text:
string content = reader.ReadToEnd(); PdfDocument doc = new PdfDocument(); AcmRender render = new AcmRender(doc); AcmText text = new AcmText(content); render.Render(text);
The input text has indentations and newlines that make the XML readable. These are ignored in the output. The text is fit into the fewest line possible.
How do we preserve the formatting of the XML?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi, The easiest way to do this is to format a HTML string with your XML embedded and then use HtmlToPdf.ConvertHtml to render that HTML string. You can use the following HTML template:
Code: HTML/ASPX
<html>
<head>
<style>
textarea {
border: 0 none white;
overflow: hidden;
padding: 0;
outline: none;
resize: none;
width: 1000px;
}
</style>
</head>
<body>
<textarea id="container">
xml contents goes here
</textarea>
<script>
var container = document.getElementById("container");
container.style.height = "auto";
container.style.height = container.scrollHeight + "px";
</script>
</body>
</html>
You will need to: 1. Replace the width attribute of the textarea CSS style to your desired width; 2. Replace "xml contents goes here" with your actual XML contents; After that you can simply call the following code:
Code: C#
HtmlToPdf.ConvertHtml(html_with_xml, result_pdf_file);
This should preserve all the indentations in your original XML. Please let us know if this works for you. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 10/20/2022 Posts: 5
|
It works. Thanks.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Great. In our next build you will be able to call ConvertUrl on an XML file directly and it will be rendered with proper indentiation in the result PDF file.
|
|
Rank: Newbie Groups: Member
Joined: 10/20/2022 Posts: 5
|
There is a problem with this solution. It cuts off the text. Not always, but sometimes. As far as I can see, I can not upload pictures here, so I will try to describe it.
This input: <ST26SequenceListing originalFreeTextLanguageCode="en" nonEnglishFreeTextLanguageCode="ru" dtdVersion="V1_3" fileName="Exemplary DNA and AA project" softwareName="WIPO Sequence" softwareVersion="1.1.0-beta4" productionDate="2021-06-11"> (one line) Gives the expected output: <ST26SequenceListing originalFreeTextLanguageCode="en" nonEnglishFreeTextLanguageCode="ru" dtdVersion="V1_3" fileName="Exemplary DNA and AA project" softwareName="WIPO Sequence" softwareVersion="1.1.0-beta4" productionDate="2021-06-11"> (three lines)
But this input: <InventionTitle languageCode="en">Copolymer including uncharged hydropfilic block</InventionTitle> <SequenceTotalQuantity>2</SequenceTotalQuantity> Gives this output: <InventionTitle languageCode="en">Copolymer including uncharged hydropfilic block</Invent <SequenceTotalQuantity>2</SequenceTotalQuantity>
The first line is cut off at the right end.
Also, at a page break, a line is split horizontally between the pages. The upper pixels are on the first page, the lower pixels on the second page. No information is lost, but it does not look professional.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi,
Yes. With our next build you will be able to call ConvertUrl on the XML file directly and you would not have this problem. We should have it out in a few weeks.
Also we did notice a problem with your license. We will PM you with more details.
Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi, We have posted a new build that would allow you to convert XML file directly. You can download the new build from our download page. With this build you can use the following code:
Code: C#
//Make sure the converter does not try to scale out to avoid line breaks
HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.None;
//This line will fail with previous versions but will work with the new version
HtmlToPdf.ConvertUrl(xml_file_name, pdf_file_name);
Please note that this is the first build of the 2023 release cycle. So it requires a different license key. As such if you use a license key from a previous release, make sure you update your license key first. Thanks!
|
|