Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Print as PDF

$
0
0
Greetings,

I'm attempting to reproduce the behavior of "Print" as PDF using the flattening functionnality (did not find another way) but I'm having a bit of trouble.

Test Case 1 (using Adobe Pro): 

In Adobe PRO, Open the Form_Merged.pdf - From the File menu select Print - Print to any PDF driver (ie CutePDF, Adode PDF printer, ...). (Attached Form_Merged_ResultExpected.pdf)

Test Case 2 (using Aspose.PDF 8.5.0):

            l_pdfDoc = new Aspose.Pdf.Document(p_sourceFilePath);

            l_pdfDoc.Flatten();

            l_pdfDoc.Save(p_destinationFilePath);

            l_pdfDoc.Dispose();

            l_pdfDoc = null;

(Attached Form_Merged_Flattened.pdf)

Results compared:

I was expecting identical results and I believe the Flattening is the key because most of the result is 90% correct. The remaining problems are:
  1. Section 2: Text field <legal.RefPlanText> (value=“Related Plan Number:”) is defined as HIDDEN / Read Only but becomes visible when flattened. Should remain hidden after flattening.
  2. Section 4: There is a checkbox <terms.c> (value=CHECKED) defined as HIDDEN / Read Only which becomes visible after flattening. Should remain hidden.
  3. Sections 5, 6, 7: The interactive button <appendForm.E> (value=“Use Schedule”) is defined as “Visible but doesn’t print”. The expected behavior would be to have this button hidden or removed when flattened. (similar buttons that behave as expected include <agent_set_final>, <agent_import_profile>,<legal.insertNOPIDNUMBR>, <pickup_stc>, <appendForm.E7>,<appendForm.E2>, <appendForm.E4>
  4. Bottom right corner of Page 1: There is a gray text field <formtag.c.0> which is defined as HIDDEN / Required. This field shows up as a gray box after flattening but should remain hidden.

     Other fields marked as HIDDEN would also appears after flattening if a value was merged beforehand like the <EXTERNAL-KEY-REFERENCE>.

  5. Page 2: The page index field <E2_1.Form_E2.form_E2.pageNum> and the total page count < E2_1.Form_E2.form_E2.numpages> in the top right corner are defined as Visible / Read Only but the become Hidden after flattening. Similar fields on the first page remain visible. In other tests, subsequent pages with similar field would also display correctly after flattening.

Alternative Code attempted:

l_pdfDoc = new Aspose.Pdf.Document(p_sourceFilePath);

            Aspose.Pdf.InteractiveFeatures.Forms.Field[] l_formFields = l_pdfDoc.Form.Fields;

            foreach (Aspose.Pdf.InteractiveFeatures.Forms.Field l_field in l_formFields)

            {

                if (l_field.GetType() == typeof(Aspose.Pdf.InteractiveFeatures.Forms.ButtonField) || l_field.Flags == Aspose.Pdf.InteractiveFeatures.Annotations.AnnotationFlags.Default)

                {

                    try

                    {

                       if (l_field.GetType() == typeof(Aspose.Pdf.InteractiveFeatures.Forms.ButtonField))

                            l_pdfDoc.Form.Delete(l_field);

                       else

                           l_field.Flatten();

                    }

                    catch (Exception)

                    {

                       //continue loop

                    }

                }

            }

            l_pdfDoc.Flatten();

            l_pdfDoc.Save(p_destinationFilePath);

            l_pdfDoc.Dispose();

            l_pdfDoc = null;

Questions:

Is there another way to do this using aspose?

Considering some fields behave correctly after flattening and others with same attributes and definitions do not, could that mean the "flattening" function in Aspose is incomplete?

Thank you.


Viewing all articles
Browse latest Browse all 3131

Trending Articles