Free Support Forum - aspose.com

Append Truncated Word Document to PDF

We are trying to create an auto-download for our client to combines database information with an uploaded Word document. We are currently using the following code to create the first page of the PDF:


// Create a pdf docuemnt object
Pdf pdf = new Pdf();

// Base directory of local images,
pdf.FoImagePath = MapPath(".");

// Bind XML & XSL file into the Pdf instance using BindFo
pdf.BindFO(xmlResult, xslPath);
pdf.IsTruetypeFontMapCached = true;
pdf.TruetypeFontMapPath = Path.GetTempPath();

I can also create a Word Document and check it’s pageCount. If doc.pagecount > 4 our client ONLY wants us to append the first four pages to the pdf document for their review.

How do I truncate an Aspose.Words document and then append it to the pdf file we’ve created thus far?

Hello,

Thank you for your request.
I would like to note that you are using the old version of the Aspose.Words. We strongly recommend that you use the latest version of the product. You can download it here: http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx. In the latest version you can easily save documents in pdf. Please see this article here: http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-convert-a-document-to-pdf.html.

Regarding your question you can use the Pdf.Kit. You can learn how to use it from here: http://www.aspose.com/documentation/.net-components/aspose.pdf.kit-for-.net/working-with-pdf-documents-and-pages.html.

You can download Pdf.Kit from here: http://www.aspose.com/community/files/51/.net-components/aspose.pdf.kit-for-.net/category1185.aspx

So how do I truncate a document that is over X number of pages, so that it’s only X number of pages long?

Hi

Thanks for your request. You can use code like the following:

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

// Save 10 pages of the document to PDF.

PdfSaveOptions opt = new PdfSaveOptions();

opt.PageIndex = 0;

opt.PageCount = 10;

doc.Save(@"Test001\out.pdf", opt);

Hope this helps.

Best regards,

Is there a way to stream my doc into a pdf stream so that I can then use Aspose.PDF.Kit to concatenate multiple PDF files?

Hello,

Thank you for your request.

You can use one of the overload Document.Save methods like this: http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.document.save_overload_5.html

I you have any other questions, fell free to ask.

I’m obviously NOT asking my question correctly …

I have an Aspose.Words Document object - I need to be able to add up to 4 pages of this word document to another PDF document. How do I get the Aspose.Words Document Object, into an Aspose.Pdf object? All this did was put a blank pdf file on my desktop. I don’t want a pdf file on my desktop, I need an Aspose.Pdf object so that I can then use Aspose.Pdf.Kit to concatenate it with another Aspose.Pdf object … does that make sense???

Document attachedDoc = new Document(file.Stream);
if (attachedDoc.PageCount > 4)
{
attachPageCount = 4;
}
else
{
attachPageCount = attachedDoc.PageCount;
}

using (Stream stream = File.Create(MyDir + “trial.pdf”))
{
PdfSaveOptions attachedToPDF = new PdfSaveOptions();
attachedToPDF.PageIndex = 0;
attachedToPDF.PageCount = attachPageCount;
}

Hi there,

Thanks for this additional information.

Yes this is what we have been suggesting. Please see the code below which demonstrates how to combine an output PDF from Aspose.Words with another PDF using Aspose.Pdf.Kit.

Document attachedDoc = new Document(file.Stream);<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

if (attachedDoc.PageCount > 4)

{

attachPageCount = 4;

}

else

{

attachPageCount = attachedDoc.PageCount;

}

using (Stream stream = File.Create(MyDir + "trial.pdf"))

{

PdfSaveOptions attachedToPDF = new PdfSaveOptions();

attachedToPDF.PageIndex = 0;

attachedToPDF.PageCount = attachPageCount;

attachedDoc.Save(stream, attachedtoPdf);

stream.Seek(0, SeekOrigin.Begin);

}

//Instantiating PdfFileEditor object using Aspose.Pdf.Kit

PdfFileEditor editor = new PdfFileEditor();

//Create an output stream object that will store the combined PDF to disk.

FileStream outputStream = new FileStream("Document out.pdf", FileMode.Create);

//Store all input streams in an Array

Stream[] inStreams = new Stream[] {stream, otherPdfStream};

//Call the Concatenate method

editor.Concatenate(inputStreams, outputStream);

//Close streams

stream.Close();

otherPdfStream.Close();

outputStream.Close();

If you have any further queries, please feel free to ask.

Thanks,

The issues you have found earlier (filed as WORDSNET-2978) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(96)