Quantcast
Channel: Aspose.Pdf Product Family
Viewing all 1038 articles
Browse latest View live

Setting page orientation of generated PDF based on width and height of inserted image

$
0
0
Hi there,


I'm trying to set the page orientation of the generated PDF based on the size of an image I insert. If the width is greater than the height, I'd like to flip to landscape aspect ratio.

Here's my code:

        public override void Convert(FileInfo source, FileInfo target)
        {
            Pdf pdf = new Pdf();
            Section section = pdf.Sections.Add();
            var image = new Image(section);
            section.Paragraphs.Add(image);
            image.ImageInfo.File = source.FullName;
            image.ImageInfo.ImageFileType = GetImageFileType(source);
            image.ImageInfo.Title = source.Name;

            if (image.ImageWidth > image.ImageHeight)
            {
                FlipToLandscapeOrientation(section);
            }
            pdf.Save(target.FullName);
        }

The problem here is that FlipToLandscapeOrientation() is never called because image.ImageWidth and image.ImageHeight are always 0.

How can I force these to populate with the real width and height of the image I've supplied?


Many thanks,


Bart

Images converted from PDF->TIFF are having black background color instead of white in mspaint and microsoftoffice image tools

$
0
0

 Hi,

 

We recently purchased Aspose PDF component, by using below code snippet PDF files are converted to TIFF image.

 

Converted Tiff images –

1)      Images are legitimate when it opens by using “IrfanImage”, “Microsoft office Document Imaging” tools. (Background color is : white and Text color is Black)

2)      Same images when it opens by using “mspaint”, “Windows picture & Fax Viewer” tool – Image background coming in Black and Text in White color. Actually images suppose to be having white background and black text.

 

We would need a quick solution to view converted images uniformly in all image viewing tools.  We appreciate quick response and solution.

 

Attached are:

1)      Original PDF file.( 4831 EBDRTransactionAmountDiffersForm.pdf)

2)      4831 EBDRTransactionAmountDiffersForm_AsposeConverted.tif converted one.

 

Environment: JRE 7, OS: Linux and Windows.

 

Thanks

Raghu

 

Code Snippet:

 

SimpleDateFormat dateForamt=new SimpleDateFormat("dd-MM-yy:HH:mm:ss");

            System.out.println("Image Conversion Start"+ dateForamt.format(System.currentTimeMillis()));

            //Open document

            com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("C:\\ImageConversion\\Pdf\\ImageConversionNewtry\\EBDResolutionProcessForm(8).pdf");

            //Create stream object to save the output image

java.io.OutputStream imageStream = new java.io.FileOutputStream("C:\\ImageConversion\\Pdf\\ImageConversionNewtry\\EBDResolutionProcessForm(8)_Converted.tif");

            //Create Resolution object

            com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(200);

            // instantiate TiffSettings object

            com.aspose.pdf.devices.TiffSettings tiffSettings  = new com.aspose.pdf.devices.TiffSettings();

            // set the compression of resultant TIFF image

            tiffSettings.setCompression(com.aspose.pdf.devices.CompressionType.CCITT4);

            // set the color depth for resultant image

            tiffSettings.setDepth(com.aspose.pdf.devices.ColorDepth.Format1bpp);         

            // skip blank pages while rendering PDF to TIFF

            tiffSettings.setSkipBlankPages(false);

            //Create TiffDevice object with particular resolution

            com.aspose.pdf.devices.TiffDevice   tiffDevice = new com.aspose.pdf.devices.TiffDevice(resolution,tiffSettings);

            //Convert a particular page (Page 1) and save the image to stream

            tiffDevice.process(pdfDocument,1,1, imageStream);

            //Close the stream

            imageStream.close();

            dateForamt=new SimpleDateFormat("dd-MM-yy:HH:mm:ss");

            System.out.println("After Save IMAGE"+ dateForamt.format(System.currentTimeMillis()));

 

 

Issue with getCharacterSpacing() and getLineSpacing() in Aspose.pdf for Java

$
0
0
Hi,

I am using the below code to validate pdfs if the character spacing and line spacing are different. I have used multiple pdfs but getCharacterSpacing() and getLineSpacing() always return 0.0 as the result.

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("test.pdf");
com.aspose.pdf.TextFragmentAbsorber textAbsorber = new com.aspose.pdf.TextFragmentAbsorber("[\\S]+");
// Set text search option to specify regular expression usage
com.aspose.pdf.TextSearchOptions textSearchOptions = new com.aspose.pdf.TextSearchOptions(true);
textAbsorber.setTextSearchOptions(textSearchOptions);

pdfDocument.getPages().accept(textAbsorber);

// Loop through the Text fragments
for (com.aspose.pdf.TextFragment textFragment : (Iterable<com.aspose.pdf.TextFragment>) textAbsorber.getTextFragments()) {
System.out.println("Character Spacing :- " + textFragment.getTextState().getCharacterSpacing());
System.out.println("Line Spacing :- " + textFragment.getTextState().getLineSpacing());
System.out.println("Font - Name :- " + textFragment.getTextState().getFont().getFontName());
System.out.println("Font Size :- " + textFragment.getTextState().getFontSize());

}

Can you please let me know if there is a way in aspose.pdf for java to validate a pdf file for its character and line spacing.

Regards,

NullPointerException in the Form.importXml (First Time Only)

$
0
0

Hi there,

 

Aspose pdf version - aspose-pdf-10.3.0.jar

Platform – Fuse Windows, Fuse Linux

 We filling Fillable PDFs use  the following code in a camel route.

 The license is initialized as part of the spring bean afterPropertiesSet() method.

 

Document pdf = new Document(pdftemplateName);

       Formform = new Form();

       form.bindPdf(pdf);

       //import the changes to the pdf from xml stream

       InputStream xmlInputStream = xml input stream

       form.importXml(xmlInputStream);

       xmlInputStream.close();

    

       ByteArrayOutputStreambObj = new ByteArrayOutputStream();

  

       form.save(bObj);

       byte[] byteArray = bObj.toByteArray();   

The first time this code get executed we get the following null pointer exception. Successive runs of this method works for the same input xml.

java.lang.NullPointerException

at com.aspose.pdf.internal.p359.z32.m1(Unknown Source)

at com.aspose.pdf.internal.p361.z2.m1(Unknown Source)

at com.aspose.pdf.internal.p575.z11.m4(Unknown Source)

at com.aspose.pdf.internal.p575.z11.m7(Unknown Source)

at com.aspose.pdf.internal.p575.z11.m3(Unknown Source)

at com.aspose.pdf.internal.p575.z8.m1(Unknown Source)

at com.aspose.pdf.internal.p576.z12.m4(Unknown Source)

at com.aspose.pdf.internal.p576.z7.<init>(Unknown Source)

at com.aspose.pdf.internal.p576.z9.<init>(Unknown Source)

at com.aspose.pdf.internal.p576.z12.<init>(Unknown Source)

at com.aspose.pdf.internal.p575.z8.m1(Unknown Source)

at com.aspose.pdf.internal.p578.z27.m28(Unknown Source)

at com.aspose.pdf.internal.p578.z27.m1(Unknown Source)

at com.aspose.pdf.internal.p578.z29.m1(Unknown Source)

at com.aspose.pdf.internal.p578.z27.m1(Unknown Source)

at com.aspose.pdf.internal.p580.z1.m1(Unknown Source)

at com.aspose.pdf.internal.p579.z4.m1(Unknown Source)

at com.aspose.pdf.internal.p580.z1.m1(Unknown Source)

at com.aspose.pdf.internal.p580.z1.m2(Unknown Source)

at com.aspose.pdf.TextBoxField.m2(Unknown Source)

at com.aspose.pdf.WidgetAnnotation.m1(Unknown Source)

at com.aspose.pdf.Field.updateAppearances(Unknown Source)

at com.aspose.pdf.Field.m6(Unknown Source)

at com.aspose.pdf.Field.setValue(Unknown Source)

at com.aspose.pdf.TextBoxField.setValue(Unknown Source)

at com.aspose.pdf.facades.AForm.m2(Unknown Source)

at com.aspose.pdf.facades.AForm.importXml(Unknown Source)

at com.aspose.pdf.facades.Form.importXml(Unknown Source)


Input xml:

 <?xml version="1.0" encoding="UTF-8"?>

<fieldsxmlns:docfun="http://wwww.connecture.com/integration/docgen"
    xmlns:dyn="http://exslt.org/dynamic"xmlns:fn="http://www.w3.org/2005/xpath-functions"
    xmlns:gsp="http://groovy.codehaus.org/2005/gsp">
   
<field name="Applicant_Signature">
       
<value>PrimaryFName, PrimaryLName</value>
   
</field>
</fields>

 Thanks.

Aspose XFDF to PDF conversion

$
0
0
Hello,

We are using Aspose to convert XFDF file to PDF file. In the XFDF file, we are setting a value of 1 or 0 to indicate the check box selection (1 = checked, 0 = unchecked) for the check box fields; this is causing an issue while converting the PDF file from the XFDF as the Aspose is treating 1 or 0 as a value and checking (selecting) all the check boxes (including unchecked ones) in the PDF after conversion.

The default values in XFDF for check boxes are On and Off for check and un-check respectively, is it possible to configure Aspose to accept 1 or 0 instead of On or Off?

I appreciate your help on this.

Set Characters per horizontal and vertical inch

$
0
0
Hi,

I wanted to check if in aspose there is a way to set characters per horizontal inch and lines per vertical inch.

Regards,

Losing layers when converting

$
0
0
Hi,

One of our customers had an issue where some pdfs were not converted properly and one of the layers (containing text) was lost. I managed to reproduce this issue when attempting to convert this pdf to jpeg, tiff and even to pdf/a. The resulting image was always the same.

Attached is a sample pdf

For jpeg conversion I used below code:

                        // Open document
                        Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(srcFile);
                        pdfDocument.Flatten();

                        for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
                        {
                            String jpegName = Path.Combine(Path.GetDirectoryName(destFile), Path.GetFileNameWithoutExtension(destFile) + "_" + pageCount + ".jpg");
                            using (FileStream imageStream = new FileStream(jpegName, FileMode.Create))
                            {
                                // Create Resolution object
                                Resolution resolution = new Resolution(settings.JpegSettings.Resolution);
                                // Create JPEG device with specified attributes (Width, Height, Resolution, Quality)
                                // where Quality [0-100], 100 is Maximum
                                JpegDevice jpegDevice = new JpegDevice(resolution, settings.JpegSettings.JpegQuality);

                                // Convert a particular page and save the image to stream
                                jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);
                                // Close stream
                                imageStream.Close();
                            }
                            files.Add(jpegName);
                        }
  
I have attempted pdfDocument.Flatten() which made no difference.
When checking the layers property (pdfDocument.Pages[1].Layers) it returns null.

When playing around in Adobe Reader after converting this pdf to pdf/a it seems the text is placed behind the background. It is still selectable but not visible.

How could this be resolved?

Best Regards

FloatingBox is postioned on next page

$
0
0
Hi Aspose,

your banckle chat asked me to redirect my problem to the forum.
I looking for a workaround of following problem, or maybe I'm doing something wrong.

I put Text into Table.Cell.
I flag some of the Texts with a paragraph relative FloatingBox at the right margin.
The FloatingBox is the successor Paragraph of the upper Table.

I observe that if the content of the cell touches the lower margin, the floating box seems to displayed on the right vertical position on the next page. You can observe this in the table of chapter 1.2.4 in the attached PDF.

I can share only my document and the floating box code which is creating all images in FloatingBoxes on the right margin.

private Paragraph GenerateStatusBoxRight(IPDFSection sectionParagraph parentSizeF statusIconSize)    {      FloatingBox statusBoxRight = new FloatingBox(section.Section.PageInfo.Margin.RightstatusIconSize.Height + parent.Margin.Top);      section.Section.Paragraphs.Add(statusBoxRight);      statusBoxRight.PositioningType = PositioningType.ParagraphRelative;      statusBoxRight.BoxVerticalPositioning = BoxVerticalPositioningType.Paragraph;      statusBoxRight.ReferenceParagraphID = parent.ID;      statusBoxRight.BoxHorizontalPositioning = BoxHorizontalPositioningType.Page;      statusBoxRight.BoxHorizontalAlignment = BoxHorizontalAlignmentType.Right;      Image image = StatusDisplay.StatusToImage(myReportItemStatus.Statusfalse);      image.ImageInfo.Alignment = AlignmentType.Center;      image.Margin.Top = parent.Margin.Top;      statusBoxRight.Paragraphs.Add(image);     #if ! SHOWTABLES      statusBoxRight.Border = new BorderInfo((intBorderSide.Allnew Aspose.Pdf.Generator.Color("MediumBlue"));#endif      return statusBoxRight;    }
I'm using aspose.pdf 10.5.0.0

Converting HTML to PDF by saving to MemoryStream

$
0
0
I'm trying to convert an Html- into a PDF document, but no matter which approach I tried, I'm getting one of these errors:
You are in direct-to-file mode,please use Close() instead of Save(). (Pdf pdf = new Pdf(), then BindToHtml and save to MemoryStream)
OR
Input stream for html data must be FileStream (Document pdfDocument = new Document(memoryStream, htmlOptions))
The HTML is converted into a byte array, 
written into a MemoryStream,
should now be converted to PDF by creating Document/Pdf saving into a new MemoryStream
and finally returned as a byte array to be stored in SharePoint.
I'm using 7.9.0.0 and it is not possibly to save the PDF to a harddrive.
The tricky part seems to be that I get a byte array and want to save the PDF to a MemoryStream...
I appreciate any help.

Re: PDFANDROID-176 (Text is not bold, line isn't seen)

$
0
0
Hi,

We have tested the scenario again with the 1.7.0 version and its working for text to be Bold. So thank you for that, but when we are using the latest version 1.7.0 we are facing the issue that I mentioned before i.e it is taking too much time to generate the PDF as compared to version 1.6.0. So can you please suggest any alternative solution why we are facing the issue in 1.7.0 and not in 1.6.0. 

Thanks,

PDF-png: Yellow icon that indicates there is a comment in the png but not exist in original PDF

$
0
0
Hi,

 A yellow icon that indicates there is a comment in the converted png image but not exist in original PDF. PFA for reference. See page iv in the original PDF file and observe there is no comment section but converted png image has one..


Replace text is now working aspose.pdf java

$
0
0
Hi,

I was trying to replace the text using pdfContentEditor and also with TextFragmentAbsorber in the existing pdf file.

After replacing the text, i could see only few chars displayed(i.e. many characters are missing) in the updated pdf file.

Please let me know if anything missing during the replace text.

below is the code snippet am using for this.
        com.aspose.pdf.facades.PdfContentEditor pdfContentEditor = new com.aspose.pdf.facades.PdfContentEditor();
        pdfContentEditor.bindPdf(doc);
        pdfContentEditor.replaceText("#UPPER LETTERS1#",1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
        pdfContentEditor.replaceText("#lower letters2#",1, "abcdefghijklmnopqrstuvwxyz");
        pdfContentEditor.save(outFile);


Note: When I copy the text from pdf, and paste in any editor, am able to see all characters.

Thanks,
Shivaji

Pdf image replace JBIG2

$
0
0
Hi,

We are trying to optimize our pdf compression.

According to this link:

http://www.aspose.com/docs/display/pdfnet/Identify+if+image+inside+PDF+is+Colored+or+Black+&+White

Different type of compression can be applied over images to reduce their size. The type of compression being applied over image depends upon the ColorSpace of source image i.e. if image is Color (RGB), then apply JPEG2000 compression, and if it is Black & White, then JBIG2/JBIG2000 compression should be applied. Therefore identifying each image type and using an appropriate type of compression will create best/optimized output.

Does Aspose provide all functionality to apply these compressions?

In the following code snippet I tried to replace the jpeg of the pdf by the same image with JBIG2 compression generated by another library. However when looking at the result the original pdf (601 KB) is now 1525 KB after adding the JBIG2 jpeg file (84 KB). I extracted the JPEG image again after the replacement and the result JPEG is 435 KB, 150 dpi instead of 300, full color instead of B/W and also unreadable. Is there a way to replace an image without these alterations?

I also added the result pdf we are trying to achieve, which was generated by another application, which is B/W, 300 dpi and only 32 KB.

Below is the code I used for this test. I have been playing around with the optimization settings but without a satisfying result.

Am I missing something? 

private void CompressPdf()
        {
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document("Original.pdf");
            foreach (Page page in doc.Pages)
            {
                int idx = 1;
                foreach (XImage image in page.Resources.Images)
                {
                    using (var fileStream = new FileStream("JBIG2.jpeg", FileMode.Open, FileAccess.ReadWrite))
                    {
                        page.Resources.Images.Replace(idx, fileStream);
                    }

                    //using (var imageStream = new MemoryStream())
                    //{
                    //    // To compress images change the image type and resolution
                    //    image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png, 72);
                    //    imageStream.Seek(0, System.IO.SeekOrigin.Begin);
                    //    // Control image quality for better compression
                    //    page.Resources.Images.Replace(idx, imageStream, 80);
                    //}
                    idx = idx + 1;
                }

                //Output JBIG file after replace in pdf
                using (var fileStream = new FileStream("JBIG2 After replace.jpeg", FileMode.CreateNew, FileAccess.ReadWrite))
                {
                    page.Resources.Images[1].Save(fileStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                }
            }

            // Load source PDF file
            Aspose.Pdf.Document document = new Aspose.Pdf.Document(sFile);
            // Optimzie the file size by removing unused objects
            doc.OptimizeResources(new Aspose.Pdf.Document.OptimizationOptions()
            {
                LinkDuplcateStreams = true,
                RemoveUnusedObjects = true,
                RemoveUnusedStreams = true,
                CompressImages = false                
            });
            
            // Save the updated file
            doc.Save("result.pdf");
        }

Best Regards

Which function should I use to get whether there is a XFA form in my PDF document?

$
0
0
Hi. I am new to Aspose. Is there any function that I can use in Aspose.PDF that can return whether there is a XFA form in my interactive form fields? Thanks in advance

Issues with flattening a PDF

$
0
0
Hi, I'm evaluating the Aspose PDF/Java library.  I have a need to convert PDF's for archiving (PDF/A, flattened forms, etc).  The library seems to be doing most of what I need, but I'm having issues with a few documents.   I've attached one that has about 20 pages of forms.  The curious thing is that the vast majority of the document is flattened with no issues, however the forms on the first page seem to have lost some of their values. 

I tried calling Form.flattenAllFields() per the documentation, as well as grabbing all the fields, iterating through them and calling Form.flattenField() directly (which flattenAllFields() probably does internally). 

Another potential problem is performance.  The flattening process is really slow.  I don't know if there are some ways to speed this up.  I was thinking of getting the field list then calling Form.flattenField() using multiple threads, I just don't know if the API can handle concurrent flattenField calls.


Images converted from PDF-&gt;TIFF are having black background color instead of white in mspaint and microsoftoffice image tools

$
0
0

 Hi,

 

We recently purchased Aspose PDF component, by using below code snippet PDF files are converted to TIFF image.

 

Converted Tiff images –

1)      Images are legitimate when it opens by using “IrfanImage”, “Microsoft office Document Imaging” tools. (Background color is : white and Text color is Black)

2)      Same images when it opens by using “mspaint”, “Windows picture & Fax Viewer” tool – Image background coming in Black and Text in White color. Actually images suppose to be having white background and black text.

 

We would need a quick solution to view converted images uniformly in all image viewing tools.  We appreciate quick response and solution.

 

Attached are:

1)      Original PDF file.( 4831 EBDRTransactionAmountDiffersForm.pdf)

2)      4831 EBDRTransactionAmountDiffersForm_AsposeConverted.tif converted one.

 

Environment: JRE 7, OS: Linux and Windows.

 

Thanks

Raghu

 

Code Snippet:

 

SimpleDateFormat dateForamt=new SimpleDateFormat("dd-MM-yy:HH:mm:ss");

            System.out.println("Image Conversion Start"+ dateForamt.format(System.currentTimeMillis()));

            //Open document

            com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("C:\\ImageConversion\\Pdf\\ImageConversionNewtry\\EBDResolutionProcessForm(8).pdf");

            //Create stream object to save the output image

java.io.OutputStream imageStream = new java.io.FileOutputStream("C:\\ImageConversion\\Pdf\\ImageConversionNewtry\\EBDResolutionProcessForm(8)_Converted.tif");

            //Create Resolution object

            com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(200);

            // instantiate TiffSettings object

            com.aspose.pdf.devices.TiffSettings tiffSettings  = new com.aspose.pdf.devices.TiffSettings();

            // set the compression of resultant TIFF image

            tiffSettings.setCompression(com.aspose.pdf.devices.CompressionType.CCITT4);

            // set the color depth for resultant image

            tiffSettings.setDepth(com.aspose.pdf.devices.ColorDepth.Format1bpp);         

            // skip blank pages while rendering PDF to TIFF

            tiffSettings.setSkipBlankPages(false);

            //Create TiffDevice object with particular resolution

            com.aspose.pdf.devices.TiffDevice   tiffDevice = new com.aspose.pdf.devices.TiffDevice(resolution,tiffSettings);

            //Convert a particular page (Page 1) and save the image to stream

            tiffDevice.process(pdfDocument,1,1, imageStream);

            //Close the stream

            imageStream.close();

            dateForamt=new SimpleDateFormat("dd-MM-yy:HH:mm:ss");

            System.out.println("After Save IMAGE"+ dateForamt.format(System.currentTimeMillis()));

 

 

Render to Graphic Context

$
0
0
Hello,

I'm currently evaluating your products in order to integrate different document formats into our reporting solution.

In Aspose Words a method RenderToScale exists which can be used to render to System.Drawing.Graphics.

This is very convenient for integrating the tool into a report generator.

Unfortunately, Pdf lack this functionality.

Is it not possible to render to a Graphics context?

Could you add this functionality in a future release?

I already posted the same request to the Aspose.Total forum and the team added the feature to Cells. See:

http://www.aspose.com/community/forums/thread/638102/render-to-graphic-context.aspx


If I could get the same functionality for the Pdf component, I could buy the whole package.

Best Regards,
Raphael

PdfFileSecurity adding user password when non supplied

$
0
0
Using PdfFileSecurity's method SetPrivilege(null, null. DocumentPrivilege) sets an owner password.
I remember testing it a few months ago and it did not set a password which means sometime in the last few months the behaviour changed. 
further more, what password is it setting if the input password is null??? 

PDF Bookmarks Generating in Wrong Order

$
0
0
Hi
I am using Aspose PDF 9.7, using the XML method. I'm also using Visual Studio 2010, and .NET 4.0.

I have discovered a problem that occurs when using the IsBookmarked attribute of the root Pdf element in the XML method.
If you have a section with several different level headings (1, 2, & 3 in the sample provided), and then a subsequent section has levels 1 and 3, but no level 2 headings, the level 3 heading appears under the level 2 heading from the first section in the bookmarks.

I have attached a sample XML file, and a screen capture (with notes) showing what I'm seeing.

Thanks
Chris

Multilinetext + font auto + ImportXFDF = Font size MAX

$
0
0
Hello, I'm having an issue with MultiLineText fields set to font size AUTO after data merge. The resulting text appearance has an excessive size font.

Test Case
PDF Form with 1 full page sized MultiLineText field with font size set to AUTO

Info
Win7 64bit
.NET 2.0
Aspose.PDF.dll v8.5.0.0 for .NET 2.0

Expected Result
In Adobe Acrobat Pro, when editing or filling PDF Form containing a multiline text field with size AUTO, the text maintains a font size of default (12) until the text fills the field at which point the text size will gradually reduce to accomodate all the text. This is true for manual entry and import XFDF.

Code Sample 1

Dim l_pdfForm As Aspose.Pdf.Facades.Form = Nothing
l_pdfForm = New Aspose.Pdf.Facades.Form("c:\temp\testform.pdf")
Using l_memoryStream As New MemoryStream( System.Text.Encoding.UTF8.GetBytes("c:\temp\testform_data.xfdf"))
l_pdfForm.ImportXfdf(l_memoryStream)
End Using
l_pdfForm.Save("c:\temp\TestForm_ImportXFDF_result.pdf")

Code Sample 2

Dim l_pdfForm As Aspose.Pdf.Facades.Form = Nothing
Dim l_fieldName As String = String.Empty
Dim l_fieldPath As String = String.Empty
Dim l_fieldIndex As Integer = 0
Dim l_xfdfDoc As XmlDocument = Nothing
Dim l_nsManager As XmlNamespaceManager = Nothing
Dim l_xfdfNav As XPathNavigator = Nothing
Dim l_xfdfNodeNav As XPathNavigator = Nothing

l_pdfForm = New Aspose.Pdf.Facades.Form("c:\temp\testform.pdf")
l_xfdfDoc = New XmlDocument()
l_xfdfDoc.Load("c:\temp\testform_data.xfdf")
l_nsManager = New XmlNamespaceManager(l_xfdfDoc.NameTable)
l_nsManager.AddNamespace("x", "http://ns.adobe.com/xfdf/")
l_xfdfNav = l_xfdfDoc.CreateNavigator()

For l_fieldIndex = 0 To l_pdfForm.FieldNames.Length - 1
l_fieldName = l_pdfForm.FieldNames(l_fieldIndex)
l_fieldPath = "//x:field[@name='" + String.Join("']/x:field[@name='", l_fieldName.Split("."c)) + "']/x:value"
l_xfdfNodeNav = l_xfdfNav.SelectSingleNode(l_fieldPath, l_nsManager)
If l_xfdfNodeNav IsNot Nothing Then
l_pdfForm.FillField(l_fieldName, l_xfdfNodeNav.Value)
End If
Next

l_pdfForm.Save("c:\temp\TestForm_FillField_result.pdf")

Actual Result

See attached ZIP containing the following files:
  • TestForm.pdf  (base PDF Form used as the template)
  • TestForm_data.xfdf (XFDF data to be used for the form merge)
  • TestForm_ImportXFDF_result.pdf (Result of Code Sample 1)
  • TestForm_FillField_result.pdf (Result of Code Sample 2)
Notice in the results when opening the PDF in Adobe Acrobat Pro, the text appears to have extremely large font 72+.
If you edit the field in Adobe Acrobat Pro, the font returns to normal.

I attempted to fix appearance with the following but no success: 

l_pdfEditor.Document.Form.Fields(l_fieldIndex).FitIntoRectangle = False
l_pdfEditor.Document.Form.Fields(l_fieldIndex).DefaultAppearance.FontSize = 12

I have also tried this with the latest Aspose.Pdf.dll v10.6.0.0  but I have the same problem.

How can I enforce a maximum size font (12) for a single line value of text in a multiline text field set to AUTO size?

NOTE: The font auto size behavior was working correctly in old style "importXfdf" using Aspose.Pdf.Kit.dll v 4.8.0.0.
Viewing all 1038 articles
Browse latest View live