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

Blank PDF document after merging

$
0
0
We are using aspose.PDF 11.5 and have a license. The first PDF document produces a blank page yet when the license is removed, the evaluation correctly displays the page. Here is the code:

Imports Aspose.Pdf
Imports System.IO

Public Class test
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim pdf_memoryStream As New MemoryStream
Dim ms As New IO.MemoryStream
Dim pdf_byteArray As Byte()

' commenting out the license will produce the first pdf page as an evaluation page but it's missing when there's a license
Dim license As New Aspose.Pdf.License
license.SetLicense("Aspose.Pdf.lic")

pdf_memoryStream = GenerateDocument("THIS IS THE FIRST PDF PAGE")

ms = GenerateDocument("THIS IS THE SECOND PDF PAGE")
pdf_memoryStream = ConcatenatePdf(pdf_memoryStream, ms)

ms = GenerateDocument("THIS IS THE THIRD PDF PAGE")
pdf_memoryStream = ConcatenatePdf(pdf_memoryStream, ms)

pdf_byteArray = pdf_memoryStream.ToArray()

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.OutputStream.Write(pdf_byteArray, 0, pdf_byteArray.Length)
Response.End()
End Sub

Public Shared Function ConcatenatePdf(ByVal firstMemoryStream As Stream, secondMemoryStream As Stream) As MemoryStream
Dim pdfMainDocument As New Document(firstMemoryStream)
Dim pdfDocument As New Document(secondMemoryStream)
Dim ms As New MemoryStream()

pdfMainDocument.Pages.Add(pdfDocument.Pages)
pdfMainDocument.Save(ms)
Return ms
End Function

Public Shared Function GenerateDocument(ByVal message As String) As MemoryStream
Dim pdf As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf()
Dim ms As New MemoryStream
Dim sec1 As Aspose.Pdf.Generator.Section = pdf.Sections.Add()

sec1.Paragraphs.Add(New Aspose.Pdf.Generator.Text(message))
pdf.Save(ms)
Return ms
End Function


End Class

PDF Resizing and Format Conversion Questions

$
0
0

1) Can i use the API to scale a PDF down to a PDF which is 30% of the original PDF's size.


2) Can I also use the API to convert PDF images to monochrome bitmap (BMP) file format


3) Can I use the API to change some text in the PDF


I would like to automate these functions and thus if the API were able to offer these functions it would be helpful.


Thanks

Convert PDF to PDF/A Error

$
0
0
When we try to convert PDF files to PDF/A file, the errors occurred as below.
The original file is 'a.pdf'.
#1. The image in PDF file has changed position and broken. See 'a_out1.pdf'.
#2. It couldn't save to PDF/A format.
#3. There was NULL POINT EXCEPTION error from some of PDF files.

The source code was much the same between below and your sample(http://www.aspose.com/docs/display/pdfnet/Convert+PDF+File+to+PDF-A).

privatevoid button1_Click(object sender, RoutedEventArgs e)
       {

           Aspose.Pdf.License license = new Aspose.Pdf.License();

           license.SetLicense(@"c:\batch\Aspose.Pdf.lic");

           string sfilename = @"c:\Batch\am.pdf";

           string sfilename_out = @"c:\Batch\am_out1.pdf";


           Document pdfDocument = newDocument(sfilename);

           // Convert to PDF/A compliant document

           //during conversion process, the validation is also performed

           //pdfDocument.Validate(sfilename_out,PdfFormat.PDF_A_1B);

           pdfDocument.Convert(@"C:\Batch\log.xml", PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);

          //pdfDocument.Convert("log.xml", PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);

           // Save output document

           pdfDocument.Save(sfilename_out);

Please let us know the solution for these errors.
Thank you.

setKeptWithNext is not working

$
0
0
Hi,

I am using aspose.pdf.11.5 version

I need a function to keep a headline and the following paragraph connected on the same page.
I have tried setKeptWithNext(true). But it did not work.

Here is sample code
TextFragment txt2 = new TextFragment("Next Steps1");

txt2.setMargin(new MarginInfo(0, 5, 0, 10));
txt2.getTextState().setHorizontalAlignment(HorizontalAlignment.Center);
txt2.setKeptWithNext(true);
page.getParagraphs().add(txt2);

Table table = new Table();
table.setColumnWidths("3% 97%");
table.setDefaultCellPadding(new MarginInfo(0,5,0,5));
Row row = table.getRows().add();
Cell cell = row.getCells().add("cell1");
cell.setMargin(new MarginInfo(-25,0,0,0));

Cell cel2 = row.getCells().add("cell2");

page.getParagraphs().add(table);

How can I make it work?

Thanks
Mamatha

Concatenating PDFs generated by Aspose.PDF fail with NullReferenceException

$
0
0
Concatenation fails when merging PDFs generated by Aspose.PDF .NET (11.5 for .net3.5).  I'm able to concatenate non-Aspose created PDFs without issue.

I'm using the latest version of Aspose.PDF and Aspose.Word (16.3 for .net2.0).  I'm running Windows8.1 Pro x64 with latest updates installed.  I created a .NET 3.5 console application that generates two Aspose.Word.Document using a memory stream and then saves them to PDF.  I confirm the PDF files generated are viewable and then concatenate them, but this error is thrown:

PDFIsValid = True
PDFIsValid = True
System.NullReferenceException: Object reference not set to an instance of an object.
   at Aspose.Pdf.Facades.PdfFileEditor.☻(Exception ☻)
   at Aspose.Pdf.Facades.PdfFileEditor.Concatenate(String[] inputFiles, String outputFile)
   at AsposeConcatenate.Program.Main(String[] args) in c:\Development\TrustOnline\TrustOnline\Utility\AsposeConcatenate\
AsposeConcatenate\Program.cs:line 59
No corrupted documents.

/////////////////////
using System;
using System.IO;
using Aspose.Pdf.Facades;

namespace AsposeConcatenate
{
class Program
{
static void Main(string[] args)
{
if (File.Exists("output.pdf")) File.Delete("output.pdf");
if (File.Exists("template.pdf")) File.Delete("template.pdf");
if (File.Exists("template2.pdf")) File.Delete("template2.pdf");

{
var license = new Aspose.Pdf.License();
license.SetLicense("Aspose.Total.lic");
}
{
var license = new Aspose.Words.License();
license.SetLicense("Aspose.Total.lic");
}

using (var memoryStream = new MemoryStream())
using (var writer = new StreamWriter(memoryStream))
{
writer.Write("some text");
writer.Flush();

var newDoc = new Aspose.Words.Document(memoryStream);
try
{
newDoc.Save("template.pdf", Aspose.Words.SaveFormat.Pdf);
newDoc.Save("template2.pdf", Aspose.Words.SaveFormat.Pdf);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return;
}
}

string[] filesArray = new string[2];
filesArray[0] = "template.pdf";
filesArray[1] = "template2.pdf";
// Confirm files are valid
foreach (string file in filesArray)
{
Console.WriteLine("PDFIsValid = {0}", PdfIsValid(file));
}

PdfFileEditor pdfEditor = new PdfFileEditor();
pdfEditor.CorruptedFileAction = PdfFileEditor.ConcatenateCorruptedFileAction.StopWithError;
pdfEditor.CloseConcatenatedStreams = true;
pdfEditor.AllowConcatenateExceptions = true;
try
{
bool result = pdfEditor.Concatenate(filesArray, "output.pdf");
Console.WriteLine("Concatenate Result = {0}", result);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}

if (pdfEditor.CorruptedItems.Length > 0)
{
Console.WriteLine("Corrupted documents:");
foreach (PdfFileEditor.CorruptedItem item in pdfEditor.CorruptedItems)
{
Console.WriteLine(item.Index + " reason " + item.Exception.Message);
}
}
else
{
Console.WriteLine("No corrupted documents.");
}

Console.ReadLine();
}

public static bool PdfIsValid(string fileName)
{
try
{
var doc = new Aspose.Pdf.Document(fileName);
}
catch (Exception e)
{
Console.WriteLine(e);
return false;
}
return true;
}
}
}


Exception thrown when trying to get the names of the fields in a form

$
0
0
When using Aspose.PDF to analyze the attached document sample.pdf, an exception is thrown when trying to get the names of the fields in the documents.

The code to produce the error is basically the following (in VB.NET):

Dim Document as New Aspose.Pdf.Document(SourceFile)
Dim Form as New Aspose.Pdf.Facades.Form(Document)
For Each FieldName in Form.FieldNames
' Do Something
Next

When execution attempts to enter the for loop, a System.Xml.XPath.XPathException is thrown with the message "Namespace prefix 'tmpl28' is not defined."

Is there something I can do to get the field names from the document without causing an exception?

Thanks,
Michael Whalen

Conversion from PDF to HTML using Avenir font returns blank document

$
0
0
Converting a PDF document in an Avenir font to HTML returns a blank document.

Do you have a resolution for this problem?

Regards, Janet

Aspose PDfViewe print issue

$
0
0
When using PDfViewer() object to open a pdf and use the Print() method to print it into through PDF Printer, the printed document gets converted into images (the text) instead of text
We have tried below option but output still has the images.
pdfViewer.PrintAsImage = false; FontRepository.Substitutions.Add(newSystemFontsSubstitution(SubstitutionFontCategories.TheSameNamedEmbeddedFonts));
pdfViewer.RenderingOptions.SystemFontsNativeRendering = true;
I have attached .Net sample code, input PDF file and output PDF file. Kindly help us resolve this issue at the earliest.

Converting png to pdf returns jpg

$
0
0
I am attempting to turn a png image into a pdf using the nodejs library for the cloud service. 

I am attempting to use the PutCreate and GetImageSaveAs  functions to convert an image to pdf and then save it. I have also tried with GetDownload and did not find that helpful. 

What is happening is I am receiving an jpg image back instead of a pdf and the image has a red x going from corner to corner. Here is the code I am using. 

storageApi.PutCreate(fileName, null, null, file.path, function(response) {
if (response.code !== 200) {
console.log('Uploading Error', response.body)
return deferred.reject('Unable to upload document.')
}
imagingApi.GetImageSaveAs(fileName, 'pdf', pdfName, null, null, function(response) {
if (response.code !== 200) {
console.log('Converting Error', response.body.toString('utf8'))
return deferred.reject('Unable to convert document.')
}
console.log(response.body)
var writeStream = fs.createWriteStream(pdfPlace);
writeStream.write(response.body);
deferred.resolve(pdfName);
});
});

Temporary files not being removed from /TEMP directories

$
0
0
We are finding a large number of jffi*.tmp, Aspose_*.tmp or +~JF*.tmp files left in the /TEMP directory (on Linux or Windows).

We use Aspose-Words (15.8) for Java and Aspose-PDF for Java (10.6.2 and 11.3)

Could you advise how this can be avoided or cleaned up by a threaded application and explain why they are not removed?

Thanks
Janet 



Font name is not retained

$
0
0
Hi,

I am trying to create document using font "Palatino Linotype". When I verified font properties of the pdf document, font name was converted to "PalatinoLinotype". Can you please look into it.

com.aspose.pdf.Document.addLocalFontPath(System.getenv("SystemRoot")+System.getProperty("file.separator")+"Fonts");
Font font = com.aspose.pdf.FontRepository.findFont("Palatino Linotype");
TextFragment dfgmt = new TextFragment("testing");
dfgmt.getTextState().setFont(font);

Thanks
Mamatha

PDF security - default password?

$
0
0
Hi,

I'm setting the security settings on my PDFs like this to allow print only:
pdfdoc.Security = new Aspose.Pdf.Security();
pdfdoc.Security.IsDefaultAllAllowed = false;
pdfdoc.Security.IsPrintingAllowed = true;
pdfdoc.Save(sFileName);

and was just wondering what the permissions password for the document will get set to by default? Is it nothing, or the Windows password of the user logged in? I'm using impersonation too (for saving the created PDF), so will that password get used?

Cheers.

How can I get the text in a "text block" in pdf?

$
0
0
I heard that PDF has each "text block".
The textblock iswhenIcreate apdf,
I knowthatthe unit ofspace to inserttext.

Ifsuch a thingexists,
Is it possible toextracta string from each unit of text block?

Landscape orientation with HTML to PDF

$
0
0
I am trying to convert an HTML string to PDF. It works fine, but I want it to be landscape orientation. I've followed the other posts and it makes the page landscape mode, but does not resize the content.

Here is one version of code I have used thus far:

htmlLoadOptions.PageInfo.Margin.Bottom = 10;
htmlLoadOptions.PageInfo.Margin.Top = 10;
htmlLoadOptions.PageInfo.Margin.Left = 10;
htmlLoadOptions.PageInfo.Margin.Right = 10;

var pdfDocument = new Document(inputFileStream, htmlLoadOptions);
for (var pageNumber = 1; pageNumber <= pdfDocument.Pages.Count; pageNumber++)
pdfDocument.Pages[pageNumber].SetPageSize(Aspose.Pdf.PageSize.PageLetter.Height, Aspose.Pdf.PageSize.PageLetter.Width); // A5 size

var pdfSaveOptions = new PdfSaveOptions();
pdfDocument.Save(pdfMemoryStream, pdfSaveOptions);

Issue in Pdf Search

$
0
0
Hi Team
I am facing some issue in Pdf search .Search is not working for texts which are starting and ending with special characters.I am trying to search "whipped" it is giving me results but when i am trying to search "whipped!" it is not giving any results.This occurs with all the texts ending with special characters.I have attached the pdf file i used for testing.Below is the code i have used for search a word in a pdf.


 Aspose.Pdf.Text.TextFragmentAbsorber textFragmentAbsorber = new Aspose.Pdf.Text.TextFragmentAbsorber(@"(?i)\b" + searchKeyword.Trim() + @"\b");
                //set text search option to specify regular expression usage
                Aspose.Pdf.Text.TextOptions.TextSearchOptions textSearchOptions = new Aspose.Pdf.Text.TextOptions.TextSearchOptions(true);
                textFragmentAbsorber.TextSearchOptions = textSearchOptions;
                //accept the absorber for all the pages
                inputPdfDocument.Pages.Accept(textFragmentAbsorber);
                //get the extracted text fragments
                return textFragmentAbsorber.TextFragments;

hyperlink

$
0
0
Hi,

I need to do exactly what described in this sample:

http://www.aspose.com/docs/display/pdfnet/Search+Text+Based+on+Regex+and+add+Hyperlink

I need to search for a single word inside a pdf document, highlight the word in blue and add a web hyperlink for this single word.

I was unable to use the editor.CreateWebLink with the actionName parameter (I either get a compiler error or a runtime-error) .. so I need to simply remove the actionName parameter in order to run the program ... but this is not the real issue.

My problem is that CreateWebLink always draw a box around the word ... there is no option for not drawing the box and Color.Trasparent simply is ignored and converted to black.

The result is very confusing and bad looking (see attached image) ... there is a way to add a web link without a box ?

any info/hint is appreciated ...

Luca

mht convert to pdf

Issue with converted xls to PDF file and header

$
0
0
Hi all
I'm not sure if this should be reported on the Aspose.PDF forum instead but I'm encountering a problematic issue with adding a header to a PDF that has been converted from an XLS using Aspose.Cells.  Here's the code, and the input XLS, and output PDF, As you can see, the header is rendered at the bottom incorrectly.  I know I can add headers using Aspose.Cells but this snippet below is just one step in a multistep process where many document types (word, pdf and excel files) are concatenated and then headers are added to denote page numbering in the concatenated PDF.

This is an urgent issue and I appreciate expedient feedback / resolution.
Thanks

var pdfStream = new MemoryStream();
            FileStream fs = new FileStream("c:/temp/sample excel.xlsx", FileMode.Open, FileAccess.Read);
            byte[] tmpBytes = new byte[fs.Length];
            fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length));

            MemoryStream mystream = new MemoryStream(tmpBytes);
            var wb = new Cells.Workbook(mystream);
            var saveOpt = new Cells.PdfSaveOptions(Cells.SaveFormat.Pdf);
            saveOpt.AllColumnsInOnePagePerSheet = true;

            wb.Save(pdfStream, saveOpt);

            var pdfDocument = new Aspose.Pdf.Document(pdfStream);
            
            var header = new Aspose.Pdf.HeaderFooter();
                var headerTable = new Aspose.Pdf.Table { DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1F) };
                var margin = new Aspose.Pdf.MarginInfo { Top = 5.76f, Left = 0f, Right = 0f, Bottom = 5f };
                headerTable.DefaultCellPadding = margin;
                headerTable.DefaultColumnWidth = "100"; 
                headerTable.Alignment = Aspose.Pdf.HorizontalAlignment.Center;
                var firstColWidth = 200; 
                var secondColWidth = 100;
                headerTable.ColumnWidths = firstColWidth.ToString() + " " + secondColWidth.ToString();
                var row1 = headerTable.Rows.Add();
                var dateCell = row1.Cells.Add();
                dateCell.Alignment = Aspose.Pdf.HorizontalAlignment.Left;
                var col1Text = new TextSegment("Column 1");
                var col1TextFragement = new TextFragment();
                col1TextFragement.Segments.Add(col1Text);
                dateCell.Paragraphs.Add(col1TextFragement);

                var col2 = row1.Cells.Add();
                col2.Alignment = Aspose.Pdf.HorizontalAlignment.Right;
                 var pageNumberText = new TextFragment("Page $p of $P");
                col2.Paragraphs.Add(pageNumberText);
                header.Paragraphs.Add(headerTable);
            pdfDocument.Pages[1].Header = header;
            //save output document
             pdfDocument.Save(@"C:\temp\excel_with_headers.pdf");

PdfFileSignature bindpdf with password

$
0
0
Hello,
I'm having an issue: I need to clear usage rights/signature from .pdf file, but that file is protected with password.  I'm unable to use BindPdf(Stream, string) because of its protection level. And using BindPdf(Stream) causes an error "invalid password".
How could I solve this?

using (Aspose.Pdf.Facades.PdfFileSignature pdfSign = new Aspose.Pdf.Facades.PdfFileSignature()){
 //pdfSign.BindPdf(vResultedStream, vPassword); //unaccessable
   pdfSign.BindPdf(vResultedStream); //Error "invalid password"
   try {
      if ((pdfSign.ContainsUsageRights())){
pdfSign.RemoveUsageRights();
      }
   }
   catch (Exception ex){
      string vMessage = ex.Message.ToString();
   }
   pdfSign.Document.Save(vNoSignatureStream);
}

pdf password: DCS
Aspose version: 11.2

Russian text is not rendered in aspose pdf

$
0
0
Hi,

I am trying to create a pdf file where some Russian language data need to be written but when pdf gets generated the Russian text is not showing up in the pdf file.

I have created a small POC to show you this issue.

Below is the Russian text-

рекламация 788 - Эмитент 0121082 - дилер, выполнивший ремонт 0121082

Sample Code:

  Aspose.Pdf.Generator.Table tbl = new Aspose.Pdf.Generator.Table();

            sec1.Paragraphs.Add(tbl);

            tbl.ColumnWidths = "50 50 50";

            tbl.DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 0.1F);

            tbl.Alignment = Aspose.Pdf.Generator.AlignmentType.Right;

            tbl.VerticalAlignment = Aspose.Pdf.Generator.VerticalAlignmentType.Bottom;

           //Set table border using another customized BorderInfo object

            tbl.Border = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All, 1F);

            Aspose.Pdf.Generator.Row row1 = tbl.Rows.Add();

            row1.Cells.Add("SNo");

            row1.Cells.Add("Name");

            row1.Cells.Add("Address");

           Aspose.Pdf.Generator.Row row2 = tbl.Rows.Add();

            row2.Cells.Add("123");

            row2.Cells.Add("1234");

           row2.Cells.Add("рекламация 788 - Эмитент 0121082 - дилер, выполнивший ремонт 0121082");

            pdf1.Save(@"C:\Log\Aspose.pdf");

Viewing all 1038 articles
Browse latest View live