Hi guys,
We are trying to render a document to a PDF after first removing several bookmarks using the code found here (it is bundled up inside it’s own assembly Acclipse.Merge.Service referenced in the ‘using’ section of the sample code)
The bookmarks appear to be removed fine and the resultant docx file looks okay if it is saved out to disk but the PDF which is rendered from it places some text on top of other text. I have included my sample code and demo input document. Hopefully you can shed some light on what might be going on. We are using version 8.2.0.0 of the product.
using System.Diagnostics;
using System.IO;
using Acclipse.Merge.Service;
using Aspose.Words;
namespace TestBookmarkRemoval
{
class Program
{
static void Main(string[] args)
{
MergeService mergeService = new MergeService();
string outputFile1 = "out1.pdf";
Document doc = new Document("IR3Test.docx");
mergeService.RemoveBookmarkWithContent(doc.Range.Bookmarks["TaxSummaryDeductionsSection"]);
mergeService.RemoveBookmarkWithContent(doc.Range.Bookmarks["TaxSummaryCreditsSection"]);
mergeService.RemoveBookmarkWithContent(doc.Range.Bookmarks["TaxSummaryTaxPayableSection"]);
mergeService.RemoveBookmarkWithContent(doc.Range.Bookmarks["TaxSummaryTaxPaidatSourceSection"]);
doc.Save("temp.docx");
Stream result = mergeService.CreatePDFFromAsposeDocument(new Document("temp.docx"));
using (var fileStream = new FileStream(outputFile1, FileMode.Create))
{
result.CopyTo(fileStream);
}
Process.Start(outputFile1);
}
}
public static class StreamExtensions
{
public static void CopyTo(this System.IO.Stream src, System.IO.Stream dest)
{
if (src == null)
{
throw new System.ArgumentNullException("src");
}
if (dest == null)
{
throw new System.ArgumentNullException("dest");
}
int readCount;
var buffer = new byte[32768];
while ((readCount = src.Read(buffer, 0, buffer.Length)) != 0)
{
dest.Write(buffer, 0, readCount);
}
}
}
}
(Also contained within the Acclipse.Merge.Service assembly)
public Stream CreatePDFFromAsposeDocument(Document asposeDocument)
{
Stream result = new MemoryStream();
PdfOptions op = new PdfOptions();
asposeDocument.SaveToPdf(0, asposeDocument.PageCount, result, op);
result.Position = 0;
return result;
}