We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to resize PDFLoadedDocument without losing its editable fields?

Thread ID:

Created:

Updated:

Platform:

Replies:

97973 Jan 21,2011 03:10 PM UTC Jan 25,2011 05:10 AM UTC ASP.NET Web Forms (Classic) 3
loading
Tags: PDF
kim
Asked On January 21, 2011 03:10 PM UTC

Hi there!

I tried to save a PDFLoadedDocument with editable fields (PdfLoadedForm); however, I had to resize (for mapping stuff) the PDF before I saved the PDF.

When I use the code below to save it (create a new PDF), the new PDF lost the all the editable fields (the Form = null).


How do I resize the PdfLoadedDocument without losing the editable fields?

Thanks!


public string ResizePDF(string inputPdfPath, float defaultHeight)
{
string saveToPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\MultPageForm.pdf";
if (File.Exists(inputPdfPath))
{
try
{
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputPdfPath);

float height = loadedDocument.Pages[0].Size.Height;
float ratio = defaultHeight / height;

//TEST HERE
try
{
PdfLoadedForm form = loadedDocument.Form;
foreach (object obj in form.Fields)
{
PdfLoadedTextBoxField tb = obj as PdfLoadedTextBoxField;
if (tb != null)
{
MessageBox.Show(tb.Name);
}
}
}
catch (Exception ex)
{

}
float newHeight = height * ratio;
float newWidth = loadedDocument.Pages[0].Size.Width * ratio;
System.Drawing.SizeF newSizeF = new System.Drawing.SizeF(newWidth, newHeight);


PdfDocument document = new PdfDocument();
document.PageSettings.Size = newSizeF;
document.PageSettings.Margins.All = 0;


for (int i = 0; i < loadedDocument.Pages.Count; i++)
{
PdfPage page = document.Pages.Add();
PdfGraphics g = page.Graphics;
PdfPageBase lpage = loadedDocument.Pages[i];
PdfTemplate template = lpage.CreateTemplate();
g.DrawPdfTemplate(template, System.Drawing.PointF.Empty, newSizeF);
}

{
PdfLoadedForm form = document.Form;
foreach (object obj in form.Fields)
{
PdfLoadedTextBoxField tb = obj as PdfLoadedTextBoxField;
if (tb != null)
{
MessageBox.Show(tb.Name);
}
}
}
catch (Exception ex)
{

}

document.Save(saveToPath);
document.Close(true);
loadedDocument.Close(true);
}
catch
{
//In case can not save or can not open existed file
saveToPath = string.Empty;
}
}
return saveToPath;

}



MultPageForm_8c22de52.rar

Selvakumar P [Syncfusion]
Replied On January 24, 2011 09:57 AM UTC

Hi Kim,

Thank you for using Syncfusion Products.

In Essential Pdf, while creating Pdf template from the page of a document, we do not import the interactive features such as form fields etc.. and We just import the contents from the page.

Please refer to the sample in the link below for the same.

Sample:
97973-2093017423.zip

Please let us know if you have any questions.

Regards,
Selvakumar.


kim
Replied On January 24, 2011 01:24 PM UTC

Hi Selvakumar!

Thanks for response, but that was not my question.

My question was:

"How do I resize the PdfLoadedDocument without losing the editable fields?"

The code I gave you just showed you the way I resized the PdfLoadedDocument, and it did not work.

I don't know if you know that the fields get screw up when you try to use DrawPdfTemplate.(Compare INPUT and OUTPUT. you don't see Text1 and Text2 anymore. You see only Page3Text3 => and the problem is the Pdf has Form fields, and I think that is a bug)

I would like to ask my question again:

How do I resize the PdfLoadedDocument without losing the editable fields?

Thanks!


Selvakumar P [Syncfusion]
Replied On January 25, 2011 05:10 AM UTC

Hi Kim,

Thanks for the response. As stated in the previous response, we cannot import the interactive features such as annotations, form fields etc... to the Pdf Template. So, obviously when we draw the Pdf Template, form fields are not added in this case. So, we cannot resize the loaded document without losing the editable fields.

Let us know if you have any questions.

Regards,
Selvakumar.



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;