We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Converting Aspose Words .doc document to PDF using Adobe Acrobat Distiller

Hi, we are experiencing a problem converting our documents that were produced by Aspose Words into PDFs using the distiller in Adobe Acrobat. Our process is to use Aspose Words to generate documents with data from a database inserted into them at bookmarks. The .doc files are then further modified using Microsoft Word and then converted into PDF files using the Adobe Acrobat distiller.

We do not have problems with document files that were created by Microsoft Word, only those that were created by Aspose Words.

Do you have any idea what might be causing this? The Acrobat distiller gives no error message, it just says that it encountered an error and cannot complete the conversion to PDF.

Any help you can give would be most appreciated.

Thanks!

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Did you experience this problem with all document generated by Aspose.Words? Currently I do not have Adobe Acrobat distiller. But I will investigate the issue and provide you more information.

Also please tell me which version of Aspose.Words you are using. Have you tried to use the latest version?

Best regards.

Hi Alexey,

The problem occurs on all Aspose.Word documents that have bookmarks in them that have text inserted. I'm not sure if I was looking in the correct place for the version of Aspose.Words, but I looked at the properties of the aspose.words.dll file and the version there is 4.2.2. If this isn't the current version, is there an upgrade procedure I need to follow or do I just download the DLL file for the current version and replace my existing DLL with it?

Thanks very much.

Chris.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. The latest version is Aspose.Words 6.0.0. You can download it from here:

http://www.aspose.com/community/files/51/file-format-components/aspose.words/entry154627.aspx

Every Aspose license carries a one-year subscription for free upgrades to any new versions or fixes that come out during this time. Aspose.Words 4.2.2.0 was published on 24th of April 2007. So I think you should renew your license. Please contact our sales team in Aspose.Purchase forum to learn how to renew your license.

http://www.aspose.com/community/forums/aspose.purchase/220/showforum.aspx

You also can test the latest version of Aspose.Words in evaluation mode or request temporary license to evaluate it without restrictions.

http://www.aspose.com/corporate/purchase/faqs/temporary-license.aspx

Also Adobe Distiller converts postscript files to PDF. I suppose you are using some tool to convert Word documents to postscript and then use Adobe Distiller to convert it to PDF. Please correct me if I am not right. Maybe problem occurs in Word-to-PostScript conversion tool. I am sure that Aspose.Words produces valid Word documents.

Best regards.

Hi Alexey,

Thanks for the upgrade info. I am in the process of upgrading to version 6.0.0 I hope this will help solve this issue.

The Adobe Distiller we use is part of Adobe Professional version 8 and it appears on a toolbar in Microsoft Word. It appears to convert the Microsoft Word file directly to PDF and from what I can tell there is no intermediate conversion from Word to postscript and then from postscript to PDF.

In every other way, Aspose.Words documents act exactly like Microsoft Word documents. I think even Aspose.Words documents with no bookmarks can be converted to PDF via Adobe Distiller with no problem. It just seems to be those documents with bookmarks that have text inserted.

Thanks again for all your help.

C.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I installed Adobe Acrobat Professional on my PC, but still can’t reproduce the problem. I created simple word document that contains bookmark and set text of bookmark using Aspose.Words. See code below:

Document doc = new Document(@"Test031\in.doc");

doc.Range.Bookmarks["test"].Text = "this is bookmark text";

doc.Save(@"Test031\out.doc");

Afterward I opened document using MS Word and successfully converted document to PDF.

Best regards.

Also if you still have problems. I think as a workaround you can try save your document in WML or RTF format. Maybe this helps.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Best regards.

Thanks so much Alexey. I am going to try it again with version 6.0.0 of Aspose.Words and see if that works. I have downloaded it and installed it, but now when I try producing a document with it I get the following error:

'Aspose.Words.Viewer.DocumentRenderer' is not defined

The section of code where the error occurs looks like this:

Line 1522: Dim doc As Document = New Document(word_templates_path & strTemplate)
Line 1523: Dim docBuilder As New DocumentBuilder(doc)
Line 1524: Dim docViewer As New Aspose.Words.Viewer.DocumentRenderer
Line 1525: Dim subDoc As Document
Line 1526: Dim subDocName As String

The imports statements at the top of the class module look like this:

Imports Aspose.Words

Imports Aspose.Words.ComHelper

Imports Aspose.Words.Viewer.DocumentRenderer

I notice that VB.Studio flags the DocumentRenderer imports statement. Has this namespace been changed or removed in Aspose.Words 6.0.0? If so, how can I automatically print a document that has been produced by Aspose.Words without displaying it? Currently, in my code I do this:

If strAutoPrint = "Y" Then

docViewer.Document = docMaster <== this is the Aspose.Words document

docViewer.GetPages()

docViewer.Print()

End If

I have commented this code out for now and the document is generated just fine, but I still would like to be able to automatically print documents instead of displaying them first.

Now that I have successfully generated a document using Aspose.Words 6.0.0 I will try and have it converted to a PDF using the Adobe Acrobat distiller (someone else does this for me -- I don't have Adobe on my workstation). I will let you know if it works.

Thanks for all your help!

Chris.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Aspose.Words.Viewer was replaced with Aspose.Words.Rendering. See the following link for more information.

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.rendering.html

You can print document using Document.Print method.

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.document.print_overloads.html

Best regards.

Hi Alexey,

Thanks for the info on Aspose.Words.Rendering. I will read up on it and modify my application accordingly.

In the meantime, we have tried producing a document using Aspose.Words 6.0.0 and were unsuccessful in converting it to a PDF using the distiller in Adobe Acrobat Professional 8.

I have attached the document so you can examine it and perhaps try converting it and see if you get the same error.

The attached document was produced with the following code. I have highlighted two function calls by increasing their font, InsertDocumentAtBookmark() and AppendDoc() that you sent me in an earlier post. I have included them below. Perhaps they do some sort of formatting that the distiller doesn't recognize?

Dim doc As Document = New Document(word_templates_path & strTemplate)

Dim docBuilder As New DocumentBuilder(doc)

Dim subDoc As Document

Dim subDocName As String

Dim bookmarks As BookmarkCollection = doc.Range.Bookmarks

Dim strBookmarkName As String = ""

Dim strBookmarkType As String = ""

Dim strBookmarkStyle As String = ""

For i = 0 To dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows.Count - 1

Try

strBookmarkName = dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows(i).Item("bookmark_name").ToString()

strBookmarkType = dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows(i).Item("bookmark_type").ToString()

strBookmarkStyle = dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows(i).Item("bookmark_style").ToString()

If strBookmarkType = "IN" Then ' Insert the file specified by bookmark_text at this bookmark

If strBookmarkStyle = "Bold" Then

docBuilder.Font.Bold = True

End If

subDocName = Trim(strSubstitutionDocumentPath) & Trim(dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows(i).Item("bookmark_text").ToString)

subDoc = New Document(subDocName)

InsertDocumentAtBookmark(strBookmarkName, doc, subDoc)

Else ' Normal bookmark so just write the bookmark value at the bookmark

If Not bookmarks(strBookmarkName) Is Nothing Then

docBuilder.MoveToBookmark(strBookmarkName, True, True)

If dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows(i).Item("bookmark_text") <> "" Then

If strBookmarkStyle = "Bold" Then

docBuilder.Font.Bold = True

End If

docBuilder.Write(dsTemplateParameters.Tables("bookmark" & strTemplateIndex).Rows(i).Item("bookmark_text"))

Else

If strBookmarkName Like ("*Address*") And bookmarks(strBookmarkName).Text = "" Then

' Remove blank address lines

docBuilder.MoveToBookmark(strBookmarkName)

Dim Node As Node = doc.Range.Bookmarks(strBookmarkName).BookmarkStart

Node.Remove()

docBuilder.CurrentParagraph.Remove()

End If

End If

End If

End If

Catch ex As Exception

lblError.Text = lblError.Text & " ? " & strBookmarkName & ", " & strBookmarkType & ", " & "Subdocname = " & subDocName & " " & ex.Message

Return

Finally

End Try

Next i

If j > 0 Then

doc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage

End If

AppendDoc(docMaster, doc)

Next j

docMaster.FirstSection.Remove()

--------------------------------------------------------------------------------------------------------------------------------------

Sub InsertDocumentAtBookmark(ByVal bookmarkName As String, ByVal dstDoc As Document, ByVal srcDoc As Document)

'Create DocumentBuilder

Dim builder As DocumentBuilder = New DocumentBuilder(dstDoc)

'Move cursor to bookmark and insert paragraph break

builder.MoveToBookmark(bookmarkName)

builder.Writeln()

'Content of srcdoc will be inserted after this node

Dim insertAfterNode As Node = builder.CurrentParagraph.PreviousSibling

'Content of first paragraph of srcDoc will be apended to this parafraph

Dim insertAfterParagraph As Paragraph = CType(insertAfterNode, Paragraph)

'Content of last paragraph of srcDoc will be apended to this parafraph

Dim insertBeforeParagraph As Paragraph = builder.CurrentParagraph

'We will be inserting into the parent of the destination paragraph.

Dim dstStory As CompositeNode = insertAfterNode.ParentNode

'Remove empty paragraphs from the end of document

While (Not srcDoc.LastSection.Body.LastParagraph.HasChildNodes)

srcDoc.LastSection.Body.LastParagraph.Remove()

End While

'Loop through all sections in the source document.

Dim srcSection As Section

For Each srcSection In srcDoc.Sections

'Loop through all block level nodes (paragraphs and tables) in the body of the section.

Dim srcNode As Node

For Each srcNode In srcSection.Body

'Do not insert node if it is a last empty paragarph in the section.

Dim para As Paragraph = CType(srcNode, Paragraph)

If (Not para Is Nothing) AndAlso para.IsEndOfSection AndAlso (Not para.HasChildNodes) Then

Exit For

End If

'If current paragraph is first paragraph of srcDoc

'then appent its content to insertAfterParagraph

If (para.Equals(srcDoc.FirstSection.Body.FirstParagraph)) Then

Dim node As Node

For Each node In para.ChildNodes

Dim dstNode As Node = dstDoc.ImportNode(node, True, ImportFormatMode.KeepSourceFormatting)

insertAfterParagraph.AppendChild(dstNode)

Next

'If subdocument contains only one paragraph

'then copy content of insertBeforeParagraph to insertAfterParagraph

'and remove insertBeforeParagraph

If (srcDoc.FirstSection.Body.FirstParagraph.Equals(srcDoc.LastSection.Body.LastParagraph)) Then

While (insertBeforeParagraph.HasChildNodes)

insertAfterParagraph.AppendChild(insertBeforeParagraph.FirstChild)

End While

insertBeforeParagraph.Remove()

End If

'If current paragraph is last paragraph of srcDoc

'then appent its content to insertBeforeParagraph

ElseIf (para.Equals(srcDoc.LastSection.Body.LastParagraph)) Then

Dim previouseNode As Node

Dim node As Node

For Each node In para.ChildNodes

Dim dstNode As Node = dstDoc.ImportNode(node, True, ImportFormatMode.KeepSourceFormatting)

If (previouseNode Is Nothing) Then

insertBeforeParagraph.InsertBefore(dstNode, insertBeforeParagraph.FirstChild)

Else

insertBeforeParagraph.InsertAfter(dstNode, previouseNode)

End If

previouseNode = dstNode

Next

Else

'This creates a clone of the node, suitable for insertion into the destination document.

Dim newNode As Node = dstDoc.ImportNode(srcNode, True, ImportFormatMode.KeepSourceFormatting)

'Insert new node after the reference node.

dstStory.InsertAfter(newNode, insertAfterNode)

insertAfterNode = newNode

End If

Next

Next

End Sub

-------------------------------------------------------------------------------------------------------------------------------------

Public Sub AppendDoc(ByVal dstDoc As Document, ByVal srcDoc As Document)

' Loop through all sections in the source document.

For Each srcSection As Section In srcDoc

' Importing a node creates a copy of the original node

Dim dstSection As Node = dstDoc.ImportNode(srcSection, True, ImportFormatMode.KeepSourceFormatting)

' Now the new section node can be appended to the destination document.

dstDoc.AppendChild(dstSection)

Next srcSection

End Sub

Thanks again for all your help.

C.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I am also unable to convert this document to PDF using Aspose Professional. But I can’t recreate such document on my side. Could you please attach your template for testing?

Have you tried using another format (WML or RTF)? I think this could help you to resolve this problem. Also you can try converting the document to PDF using Aspose.Words.

Best regards.

Thanks Alexey,

Unfortunately, we can't use WML or RTF formats as our users require the documents to be in Word (.doc) format. I will investigate the possiblity of using Aspose.Words to do the conversion. Is the PDF conversion process part of the Aspose.Words.Rendering namespace and is it documented in the link you sent me in one of your previous posts?

In the meantime, here is the template we used to create the document I sent you.

Thanks so much!

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I managed to reproduce the problem on my side and created new issue #6870 in our defect database. But I can’t promise you that this problem will be fixed shortly. Note that DOC format is not native for Adobe so maybe this problem should be fixed on Adobe side.

Regarding DOC to PDF conversion using Aspose.Words. Currently there are two ways to convert Word document to PDF.

1. Direct conversion to PDF using Aspose.Words (without using Aspose.Pdf). See the following link for more information:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.document.savetopdf_overload_1.html

here is code:

Document doc = new Document(@"Test012\number_error.doc");

doc.SaveToPdf(@"Test012\aw_out.pdf");

2. Another way is using Aspose.Words and Aspose.Pdf using the following code (Old method):

Document doc = new Document(@"Test012\number_error.doc");

//Save in intermediate AsposePdf format

MemoryStream aPdfStream = new MemoryStream();

doc.Save(aPdfStream, SaveFormat.AsposePdf);

//Create Aspose.Pdf.Pdf document

Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();

pdf.BindXML(aPdfStream, null);

//Save pdf

pdf.Save(@"Test012\out.pdf");

Best regards.

Hi Alexey,

I'm so glad you were able to re-create the problem. Thanks so much for creating a new issue for this and I do hope you are able to solve it eventually. In the meantime, I will try saving the document to PDF using the Aspose.Words doc.SaveToPdf method.

However, this will not solve my problem completely because we do additional edits to our documents after they are first produced by Aspose.Words, but before they are converted to PDFs, so we do need to keep them in the .doc format. Once the edits are approved, the documents are then converted to PDFs using the Adobe distiller. Just in case you were wondering, I did try doing exactly the same thing but using Microsoft Word to create the document instead of Aspose.Words and it successfully converted to PDF, so it's not the additional edits that are causing the problem.

I will try saving the Aspose.Words .doc document to RTF format first and then try converting the RTF file to a PDF and see how that goes.

I have logged a support call to Adobe on this issue, but I have yet to hear back from them.

Thanks again for all your help on this.

Chris.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Anyway we will investigate the issue further but I can’t promise you any timeframe. Please let me know answer of Adobe support regarding this issue.

Best regards.

Thanks for following up, Alexey.

I just discovered that Adobe has an on-line PDF conversion service, http://createpdf.adobe.com/ , which I registered with and used to successfully convert to a PDF the exact same document that I sent you! So, I suspect it is something to do with the distiller in Adobe Professional 8 and not Aspose.Words!

Which version of Adobe did you use to re-create my problem? The Adobe site shows that the most current is version 9, so I suspect they will ask me to upgrade first and see if that fixes the problem. I thought that if you used version 9, I could tell them that it didn't work with that, either.

Another thing, I discovered that I posted my support call to them in the wrong forum, so that's why I haven't heard back yet. However, I did discover their on-line conversion service as a result, so that's helped get me closer to a solution.

I'll let you know what they say.

Thanks again!

C.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I used trial version of Adobe Acrobat Professional 9.0 11.06.2008 for testing.

Best regards,

Thanks Alexey,

I will let them know. In the meantime, they suggested I try opening the document in Microsoft Word and print it to Adobe PDF. That worked, so I suspect this really is an Adobe Acrobat issue and not an Aspose.Words issue.

We will stop using the Adobe Acrobat toolbar in Word to convert documents to PDF and instead we will print them to Adobe PDF until Adobe has a chance to investigate this issue.

Thanks for spending time looking at it and installing Adobe Acrobat to help me. You guys rock! I will let you know what Adobe says.

Thx!

The issues you have found earlier (filed as 6870) have been fixed in this update.

HI Alexey,

i just want to clarify from you whether the pdf converted from word document using aspose.pdf and the pdf converted from word using adobe distiller are similar.

I got the above doubt when on of my team member reported me that the pdf generated using aspose are not properly uploaded into the distributors site whereas the pdf's generated from adobe pdf distiller are uploaded fine and appearing fine on their site.

could you please solve this issue as earliest.

iam using the aspose version 3.2

thanks

raghu