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

Free Support Forum - aspose.com

SetBookmark Image in Aspose PDF

I have a template[ResultTemplateSingleNoTrainingpdf.pdf] on which i have to produce an output pdf[result(1).docx]
.ResultTemplateSingleNoTraining-converted.pdf (118.1 KB)
Result (1).docx (71.4 KB)

Currently the output is in docx format. i need to export it in pdf format.I am uploading the function where the output to the template is set. I have bookmark feature in OpenXml for word document.
I need a similar solution for PDF tooo.
Thanx for the help.

public System.IO.Stream ExportApplicationResultDocument(string templatePath,
System.Drawing.Image spiderDiagram, //changes to System.Drawing
System.Drawing.Image bestDiagram,
System.Drawing.Image worstDiagram,
DataTable questionsDurationBestCase,
DataTable questionsDuration,
IEnumerable trainingBestTable,
IEnumerable trainingWorstTable,
string assessedLevel,
string justification,
string resultingDecisionBest,
string resultingDecisionWorst,
InternalStatus status,
string applicantFirstName,
string applicantLastName,
string applicantEadsCorpId,
System.Drawing.Image worstCaseTableImage,
System.Drawing.Image bestCaseTableImage,
string assessedDate
)
{
DataRow[] partiallyAssessedResults;
DataTable exportQuestionResults;
WordDocument doc = WordDocument.OpenCopy(File.OpenRead(templatePath), true); //template path is path to the template
//Document doc = new Document(templatePath);
foreach (WordBookmark bm in doc.GetBookmarks())
{

            switch (bm.Name)
            {
                    
                case Constants.ApplicationResult.CriterionBestDiagram:
                    if (bestDiagram != null)
                        bm.SetBookmarkImage(bestDiagram);
                    break;
                case Constants.ApplicationResult.CriterionBestTable:
                    exportQuestionResults = questionsDurationBestCase.Copy();
                    exportQuestionResults.Columns.Remove("1");
                    exportQuestionResults.Columns.Remove("2");
                    exportQuestionResults.Columns.Remove("3");
                    exportQuestionResults.Columns.Remove("4");
                    exportQuestionResults.Columns.Remove("5");
                    exportQuestionResults.Columns.Remove("6");
                    exportQuestionResults.Columns.Remove("7");
                    exportQuestionResults.Columns.Remove("8");
                    exportQuestionResults.Columns.Remove("9");
                    bm.SetBookmarkRow(exportQuestionResults, 2);
                    break;
                case Constants.ApplicationResult.CriterionWorstDiagram:
                    if (worstDiagram != null)
                        bm.SetBookmarkImage(worstDiagram);
                    break;
                case Constants.ApplicationResult.CriterionWorstTable:
                    exportQuestionResults = questionsDuration.Copy();
                    exportQuestionResults.Columns.Remove("1");
                    exportQuestionResults.Columns.Remove("2");
                    exportQuestionResults.Columns.Remove("3");
                    exportQuestionResults.Columns.Remove("4");
                    exportQuestionResults.Columns.Remove("5");
                    exportQuestionResults.Columns.Remove("6");
                    exportQuestionResults.Columns.Remove("7");
                    exportQuestionResults.Columns.Remove("8");
                    exportQuestionResults.Columns.Remove("9");
                    bm.SetBookmarkRow(exportQuestionResults, 2);
                    break;
                case Constants.ApplicationResult.TrainingBestTable:
                    if (trainingBestTable != null)
                    {
                        bm.SetBookmarkRow(trainingBestTable, 2, "Title", "Duration");
                    }
                    break;
                case Constants.ApplicationResult.TrainingWorstTable:
                    if (trainingWorstTable != null)
                    {
                        bm.SetBookmarkRow(trainingWorstTable, 2, "Title", "Duration");
                    }
                    break;
                case Constants.ApplicationResult.AssessedLevel:
                    if (status.Equals(InternalStatus.SelfAssessed))
                    {
                        bm.Text = string.Empty;
                    }
                    else
                    {
                        bm.Text = assessedLevel;
                    }
                    break;
                case Constants.ApplicationResult.Justification:
                    if (status.Equals(InternalStatus.SelfAssessed))
                    {
                        bm.Text = string.Empty;
                    }
                    else
                    {
                        bm.Text = justification;
                    }
                    break;
                case Constants.ApplicationResult.AssessmentDate:
                    if (status.Equals(InternalStatus.SelfAssessed))
                    {
                        bm.Text = string.Empty;
                    }
                    else
                    {
                        bm.Text = assessedDate;
                    }
                    break;
                case Constants.ApplicationResult.ResultingDecisionBestCase:
                    if (status.Equals(InternalStatus.SelfAssessed))
                    {
                        bm.Text = string.Empty;
                    }
                    else
                    {
                        bm.Text = resultingDecisionBest;
                    }
                    break;
                case Constants.ApplicationResult.ResultingDecisionHeader:
                    if (status.Equals(InternalStatus.SelfAssessed))
                    {
                        bm.Text = string.Empty;
                    }
                    break;
                case Constants.ApplicationResult.AssessedLevelHeader:
                    if (status.Equals(InternalStatus.SelfAssessed))
                    {
                        bm.Text = string.Empty;
                    }
                    break;
                case Constants.ApplicationResult.JustificationHeader:
                    if (status.Equals(InternalStatus.SelfAssessed))
                    {
                        bm.Text = string.Empty;
                    }
                    break;
                case Constants.ApplicationResult.ResultingDecisionWorstCase:
                    bm.Text = resultingDecisionWorst;
                    break;
                case Constants.ApplicationResult.SpiderDiagram:
                    if (spiderDiagram != null)
                        bm.SetBookmarkImage(spiderDiagram);
                    break;
                case Constants.ApplicationResult.GenericDisciplineWorst:
                    var query = from DataRow question in questionsDuration.Rows where ((string)question["GenericDiscipline"]).ToLower() != "none" select (string)question["GenericDiscipline"];
                    bm.Text = query.Distinct().Count().ToString();
                    break;
                case Constants.ApplicationResult.GenericDisciplineBest:
                    var queryBest = from DataRow question in questionsDurationBestCase.Rows where ((string)question["GenericDiscipline"]).ToLower() != "none" select (string)question["GenericDiscipline"];
                    bm.Text = queryBest.Distinct().Count().ToString();                     
                    break;
                case Constants.ApplicationResult.Q1SumWorst:
                    bm.Text = questionsDuration.Compute(string.Format(Constants.Format.ComputeSumPattern, "1"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q1SumBest:
                    bm.Text = questionsDurationBestCase.Compute(string.Format(Constants.Format.ComputeSumPattern, "1"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q2BisSumWorst:
                    bm.Text = "";
                    break;
                case Constants.ApplicationResult.Q2BisSumBest:
                    bm.Text = "";
                    break;
                case Constants.ApplicationResult.Q2SumWorst:
                    bm.Text = questionsDuration.Compute(string.Format(Constants.Format.ComputeSumPattern, "2"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q2SumBest:
                    bm.Text = questionsDurationBestCase.Compute(string.Format(Constants.Format.ComputeSumPattern, "2"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q3SumWorst:
                    bm.Text = questionsDuration.Compute(string.Format(Constants.Format.ComputeSumPattern, "3"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q3SumBest:
                    bm.Text = questionsDurationBestCase.Compute(string.Format(Constants.Format.ComputeSumPattern, "3"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q4SumWorst:
                    bm.Text = questionsDuration.Compute(string.Format(Constants.Format.ComputeSumPattern, "4"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q4SumBest:
                    bm.Text = questionsDurationBestCase.Compute(string.Format(Constants.Format.ComputeSumPattern, "4"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q5SumWorst:
                    bm.Text = questionsDuration.Compute(string.Format(Constants.Format.ComputeSumPattern, "5"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q5SumBest:
                    bm.Text = questionsDurationBestCase.Compute(string.Format(Constants.Format.ComputeSumPattern, "5"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q6SumWorst:
                    bm.Text = questionsDuration.Compute(string.Format(Constants.Format.ComputeSumPattern, "6"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q6SumBest:
                    bm.Text = questionsDurationBestCase.Compute(string.Format(Constants.Format.ComputeSumPattern, "6"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q7SumWorst:
                    bm.Text = questionsDuration.Compute(string.Format(Constants.Format.ComputeSumPattern, "7"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q7SumBest:
                    bm.Text = questionsDurationBestCase.Compute(string.Format(Constants.Format.ComputeSumPattern, "7"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q8SumWorst:
                    bm.Text = questionsDuration.Compute(string.Format(Constants.Format.ComputeSumPattern, "8"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q8SumBest:
                    bm.Text = questionsDurationBestCase.Compute(string.Format(Constants.Format.ComputeSumPattern, "8"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q9SumWorst:
                    bm.Text = questionsDuration.Compute(string.Format(Constants.Format.ComputeSumPattern, "9"), null).ToString();
                    break;
                case Constants.ApplicationResult.Q9SumBest:
                    bm.Text = questionsDurationBestCase.Compute(string.Format(Constants.Format.ComputeSumPattern, "9"), null).ToString();
                    break;
                case Constants.ApplicationResult.ApplicantName:
                    bm.Text = string.Format("{0} {1}", applicantFirstName, applicantLastName);
                    break;
                case Constants.ApplicationResult.ApplicantEADSCorpId:
                    bm.Text = applicantEadsCorpId;
                    break;
                case Constants.ApplicationResult.TrainingBestSum:
                    if (trainingBestTable != null)
                    {
                        bm.Text = trainingBestTable.Sum(t => t.Duration).ToString();
                    }
                    break;
                case Constants.ApplicationResult.TrainingWorstSum:
                    if (trainingWorstTable != null)
                    {
                        bm.Text = trainingWorstTable.Sum(t => t.Duration).ToString();
                    }
                    break;
                case Constants.ApplicationResult.LabelPartialAssessorPercent:
                    // Search for partially assessed results (displayed values ends with *)
                    partiallyAssessedResults = questionsDurationBestCase.Select("[1Display] LIKE '*[*]'"
                        + " OR [2Display] LIKE '*[*]'"
                        + " OR [3Display] LIKE '*[*]'"
                        + " OR [4Display] LIKE '*[*]'"
                        + " OR [5Display] LIKE '*[*]'"
                        + " OR [6Display] LIKE '*[*]'"
                        + " OR [7Display] LIKE '*[*]'"
                        + " OR [8Display] LIKE '*[*]'"
                        + " OR [9Display] LIKE '*[*]'");
                    if (partiallyAssessedResults.Length == 0)
                    {
                        bm.Text = string.Empty;
                    }
                    break;
                case Constants.ApplicationResult.LabelPartialAssessorPercentBestCase:
                    // Search for partially assessed results (displayed values ends with *)
                    partiallyAssessedResults = questionsDuration.Select("[1Display] LIKE '*[*]'"
                        + " OR [2Display] LIKE '*[*]'"
                        + " OR [3Display] LIKE '*[*]'"
                        + " OR [4Display] LIKE '*[*]'"
                        + " OR [5Display] LIKE '*[*]'"
                        + " OR [6Display] LIKE '*[*]'"
                        + " OR [7Display] LIKE '*[*]'"
                        + " OR [8Display] LIKE '*[*]'"
                        + " OR [9Display] LIKE '*[*]'");
                    if (partiallyAssessedResults.Length == 0)
                    {
                        bm.Text = string.Empty;
                    }
                    break;
                case Constants.ApplicationResult.WorstCaseTable:
                    if (worstCaseTableImage != null)
                    {
                        bm.SetBookmarkImage(worstCaseTableImage);
                    }
                    break;
                case Constants.ApplicationResult.BestCaseTable:
                    if (bestCaseTableImage != null)
                    {
                        bm.SetBookmarkImage(bestCaseTableImage);
                    }
                    break;
                case Constants.ApplicationResult.ResultTitleHeader:
                    var valueResultTitle = Session["ResultTitleHeader"];
                    if (valueResultTitle != null)
                    {
                        bm.Text = valueResultTitle.ToString();
                    }
                    break;
                default:
                    break;
            }
        }

        return doc.GetStream();
    }

@arun007

You can work with bookmarks using Aspose.Words for .NET 21.9. You can insert any content into bookmark e.g. text, table, images etc. Please read the following article for more detail.

After setting content of bookmark, you can save the document to PDF using Document.Save method. Please refer to the following article.

If you face any issue, please share more detail about your requirement along with input and output documents. We will then provide you more information on it.