How to read word each page? - aspose

I know doc.Save() function save all page in one HTML file.
doc.RenderToScale() function save each page to the independent image file.
but i want read or save each page in independent HTML file,I had not idea,can you help me?

You can use the following code sample to convert each page to HTML or any other format supported by Aspose.Words.
String srcDoc = Common.DATA_DIR + "src.docx";
String dstDoc = Common.DATA_DIR + "dst {PAGE_NO}.html";
Document doc = new Document(srcDoc);
LayoutCollector layoutCollector = new LayoutCollector(doc);
// This will build layout model and collect necessary information.
doc.updatePageLayout();
// Split nodes in the document into separate pages.
DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);
// Save each page to disk as separate documents.
for (int page = 1; page <= doc.getPageCount(); page++)
{
Document pageDoc = splitter.getDocumentOfPage(page);
pageDoc.save(dstDoc.replace("{PAGE_NO}", page+""));
}
It depends on 3 other classes, which you can find in this zip file.
I work with Aspose as Developer Evangelist.

Related

using document library or form library

Sorry if my question is not good because I am new to sharepoint.
I have some document in document library I like to other people can come to library and put their comment there.
with using InfoPath designer form and repeated section and publishing form to form library I can data entry in the fields of InfoPath and upload attachment and then submit to form library and then other users can come and put their comment in the form.
now my problem is, my files are in document library and all meta data there is in document library. now my question is if I want to put comments on each Document i have to make a form library and again data entry all meta data in InfoPath form and upload attachments,....and then publish.
it seems it is a duplicate job, I like to know what is the best practice in this case?
I like to know I have to start with form library from scratch?
i note i am using sharepoint server 2013 and InfoPath from.
I think I found my answer in the below link address:
[Uploading File Attachment Into a Folder in a SharePoint Document Library Using InfoPath Form][1]
, with uploading InfoPath attachments in separate document library my problem will be solved. because i wanted my files in the document library folders and also can use features of InfoPath form with using repeated section.
now at first i use InfoPath from in form library and attach required files and then after submitting, the attaches files will be upload in document library of sharepoint.
also I found in the book (infopath with sharepoint 2013 how to) appendix B:
Appendix B. Upload File Attachments in Forms to a Document
Library
This appendix presents a code-behind method that uploads an attached file to a separate document
library when the form is submitted. The code here was adapted from Pranab Paul’s blog on MSDN.
Form Scenario
The form used in this scenario contains a file attachment control with a field named fileAttach. There
is also a button to be used as a submit button with and ID of SubmitButton.
The user may upload a file to the form and then submit the form. There is a form library in SharePoint
to which to submit the InfoPath form instance, but there is also a document library in which the file
attached to the form needs to be uploaded. A data connection for submission has been created and
points to the form library.
The form contains code-behind and therefore must have Full Trust. It also must be published as an
Administrator-Approved form and then added to Form Services in SharePoint.
Submit Button and Code-Behind Setup
The custom submit button needs to have a rule added such that when the button is clicked the Submit
Data action is executed. Also, in the button properties you need to click Edit Code to produce the
button event handler and method in the code-behind:
Click here to view code image
public void InternalStartup()
{
((ButtonEvent)EventManager.ControlEvents["SubmitButton"]
).Clicked
+= new ClickedEventHandler(SubmitButton_Clicked);
}
public void SubmitButton_Clicked
(object sender, ClickedEventArgs e)
{
// Write your code here.
}
The code-behind project uses SharePoint functions and therefore needs a reference to the
Microsoft.SharePoint assembly. This is a similar requirement in the tracking changes solution
described in Chapter 17, “Track Changes in a Form,” so you may refer to those steps to include the
proper assembly reference in this file attachment solution.
Event Handler Code
Within the button event handler (SubmitButton_Clicked) you need code to perform the
retrieval of the attached file and the upload of that file to a document library. The code to perform this
is shown here:
Click here to view code image
public void SubmitButton_Clicked(object sender, ClickedEventArgs e)
{
XPathNavigator docXN = this.CreateNavigator();
XPathNavigator opnXN = docXN.SelectSingleNode("/my:myFields/my:fileAttach",
this.NamespaceManager);
byte[] attachmentNodeBytes = Convert.FromBase64String(opnXN.ToString());
// Position 20 contains a DWORD indicating the length of the
// filename buffer. The filename is stored as Unicode so the
// length is multiplied by 2.
int fnLength = attachmentNodeBytes[20] * 2;
byte[] fnBytes = new byte[fnLength];
// The actual filename starts at position 24...
for (int i = 0; i < fnBytes.Length; i++)
{
fnBytes[i] = attachmentNodeBytes[24 + i];
}
// Convert the filename bytes to a string. The string
// terminates with \0 so the actual filename is the
// original filename minus the last character !
char[] charFileName = System.Text.UnicodeEncoding.Unicode.GetChars(fnBytes);
string fileName = new string(charFileName);
fileName = fileName.Substring(0, fileName.Length - 1);
// The file is located after the header, which is 24 bytes long
// plus the length of the filename.
byte[] fileContents = new byte[attachmentNodeBytes.Length - (24 + fnLength)];
for (int i = 0; i < fileContents.Length; ++i)
{
fileContents[i] = attachmentNodeBytes[24 + fnLength + i];
}
string SiteURL = "http://SharePointRoot/DocumentLibrary/" + fileName;
SPWeb site = new SPSite(SiteURL).OpenWeb();
site.Files.Add(SiteURL, fileContents);
}
Deployment
As mentioned earlier, you need to publish the form as an Administrator-Approved form and then
upload the form template to Form Services in SharePoint. Once you upload it to Form Services, you
may use the form as the content type in the desired form library.
When a new form is instantiated and submitted, the form instance is saved in the form library you
specified in the data connection for submission, and the attached file is stored in the document library
you specified within the code-behind

Aspose.Words convert to html (only body content)

I can create word file and convert HTML with aspose.words API. How do I get the BODY content in HTML with the API (withou html,head,body tag/ only body content). I will use this to show the output in the WYSIWYG editors (summernote) application.
Note: I am developing the application with .net Framework (C#)
Document doc = new Document(MyDir + "inputdocx.docx");
var options = new Aspose.Words.Saving.HtmlSaveOptions(SaveFormat.Html)
{
ImageSavingCallback = new HandleImageSaving(),
};
String html = doc.FirstSection.Body.ToString(options);
By default, Aspose.Words saves html in Xhtml format, so you can safely load it into XmlDocument and get bydy tag’s content. For example see the following code.
// Create a simple document for testing.
DocumentBuilder builder = new DocumentBuilder();
builder.Writeln("Hello world!!!");
// For testing purposes insert an image.
builder.InsertImage(#"https://cms.admin.containerize.com/templates/aspose/App_Themes/V3/images/aspose-logo.png");
// Additional options can be specified in the corresponding save options.
HtmlSaveOptions opt = new HtmlSaveOptions(SaveFormat.Html);
// For example, output images in the HTML as base64 string (summernote supports base64)
opt.ExportImagesAsBase64 = true;
// Save the document to MemoryStream.
using (MemoryStream ms = new MemoryStream())
{
builder.Document.Save(ms, opt);
// Move the stream position ot the beginning and load the resulting HTML into Xml document.
ms.Position = 0;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(ms);
// Find body tag.
XmlNode body = xmlDoc.SelectSingleNode("//body");
// Get inner xml of the body.
Console.WriteLine(body.InnerXml);
}
Hope this helps.
Disclosure: I work at Aspose.Words team.

Aspose.PDF How Replace replace text on PDF page to all upper case

I am trying to replace text on a specific page to upper case using Aspose.PDF for .Net. If anyone can provide any help that would be great. Thank you.
My name is Tilal Ahmad and I am a developer evangelist at Aspose.
You may use the documentation link for searching and replacing text on a specific page of the PDF document. You should call the Accept method for specific page index as suggested at the bottom of the documentation. Furthermore, for replacing text with uppercase you can use ToUpper() method of String object as follows.
....
textFragment.Text = textFragment.Text.ToUpper();
....
Edit: A sample code to change text case on a specific PDF page
//open document
Document pdfDocument = new Document(myDir + "testAspose.pdf");
//create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("");
//accept the absorber for all the pages
pdfDocument.Pages[2].Accept(textFragmentAbsorber);
//get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
//loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{
//update text and other properties
textFragment.Text = textFragment.Text.ToUpper();
}
pdfDocument.Save(myDir+"replacetext_output.pdf");

How to make an text Hyperlinked using Aspose.Words DOM approach?

I am trying to create a Word document using Aspose.Words for .NET using the DOM approach. How would I make an text hyperlinked?
Like when we click on text it should be route to web page from Docx.
Example : click here
This can be done by appending a hyperlink field to the paragraph. See the below sample code
// Create or load a document
Aspose.Words.Document wordDoc = new Aspose.Words.Document();
// Get first paragraph
Aspose.Words.Paragraph para = wordDoc.FirstSection.Body.FirstParagraph;
para.Runs.Add(new Run(wordDoc, "Visit "));
// Add the hyperlink field to the paragraph
FieldHyperlink field = (FieldHyperlink)para.AppendField(Aspose.Words.Fields.FieldType.FieldHyperlink, false);
// URL
field.Address = #"""http://www.aspose.com""";
// Text
field.Result = "Aspose";
field.Update();
// Set color of the last run
para.Runs[para.Runs.Count - 1].Font.Color = System.Drawing.Color.Blue;
// Save the document
string dst = (dataDir + #"hyperlink.docx");
wordDoc.Save(dst);
I work with Aspose as Developer Evangelist.

Converting Files to PDF and attaching to another PDF in Coldfusion

So I'm doing a project that generates a PDF of information that was previously filled out in a form. Along with this information, documents were attached to support the information in the form.
I generate the PDF with the normal info from my DB, but I also want to convert their uploaded files (if .doc or .docx) to PDF format and stick in the same PDF. (So it is all in one place.)
I know how to convert to PDF, problem is how do you attach those newly generated PDFs to the current one with the other information on it?
you have 2 options:
merge all PDFs into one using <cfpdf action="merge"...>
really attach files in your main pdf but as CFPDF does not support it (yet?) you have to use iText:
<cfscript>
try {
// Source of THE main PDF and destination file
inputFile = ExpandPath("myDoc.pdf");
outputFile = ExpandPath("myDocPlusAttachments.pdf");
// the file to attach (can be of any type)
attach1 = ExpandPath("myAttachment.doc");
// prepare everything
reader = createObject("java", "com.lowagie.text.pdf.PdfReader").init( inputFile );
outStream = createObject("java", "java.io.FileOutputStream").init( outputFile );
stamper = createObject("java", "com.lowagie.text.pdf.PdfStamper").init( reader, outStream );
// attachment the file
stamper.addFileAttachment("My Attached File", javacast("null", ""), attach1, "myAttachment.doc");
// display the attachment pane when the pdf opens (Since 1.6)
writer = stamper.getWriter();
writer.setPdfVersion( writer.VERSION_1_6 );
}
finally {
// always cleanup objects
if (IsDefined("stamper")) {
stamper.close();
}
if (IsDefined("outStream")) {
outStream.close();
}
}
</cfscript>
Just found where I got that piece of code: ColdFusion 9: Adding Document Level Attachments to a PDF with iText
You need to use the CFPDF tag, and use the merge action.